worksheet.format("A2:A", { "numberFormat": { "type": "DATE_TIME" }}) doesn't work for text - gspread

I'm trying to log temperature and humidity to a google spreadsheet using gspread and python.
That works, however when I insert a row using the following code:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity))
now for example cell 'A2' has the value: '12-05-2020 00:11:50 (Note the single quotation mark)
I want the data to be represented in a chart. This cannot be done with the above value so I have to convert it to a date_time value.
worksheet.format("A2:A", { "numberFormat": { "type": "DATE_TIME" }})
I expect the entire column to be converted to Date Time. This doesn't convert the values with a single quotation mark.
I spend the whole day trying to get this to work but for some reason I can't seem to find a way to have a 'normal' date_time value added that Google Sheets recognizes as a date_time...
If I enter a (numeric) value manually in a cell in column A. The code to set the format works just fine.
Also if I manually select the column and select he formatting from the menu it works fine with the gspread added date time rows.
I really want it to be done programmatically and not by hand of course.
Any help is greatly appreciated.

In that case, please use value_input_option as follows. By this, the date is put as the date object.
From:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity))
To:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity), value_input_option="USER_ENTERED")
Reference:
append_rows(values, value_input_option='RAW', insert_data_option=None, table_range=None)
ValueInputOption

Related

Gspread append is not removing the single quote

I have switched to using gspread instead of pure google sheets api. Before i formatted my input into a json body but now i send the list direct. The append works without an error but the first item has an extra single quote on the beginning of the date.
I fell like im following the example to the letter so it seems like a bug but i wanted to ask here first just in case i'm doing something silly.
values = ['2021-08-11', '-', '-', 372, 373, 'Brayden', 'ChrisT',
'Chris', 'Dida', 'Darren', 'Ferdi', 'Bernard', 'Cal', 'Gavin',
'Conor']
ws.append_row(values)
First item in sheet: '2021-08-11
Originally using the pure api i was formatting the body as follows but as i understand it with gspread i should just be able to send the list.
body = {
'majorDimension': 'ROWS',
'values': [
google_output,
],
}
The same seems to happen if i update instead of append:
ws.update(range, values, major_dimension='ROWS')
Im using version 4.0.0 of gspread and here is the guide im following:
(method) append_row: (values, value_input_option='RAW',
insert_data_option=None, table_range=None) -> Any Adds a row to the
worksheet and populates it with values.
Widens the worksheet if there are more values than columns.
:param list values: List of values for the new row. :param str
value_input_option: (optional) Determines how the input data
should be interpreted. See ValueInputOption_ in the Sheets API reference. :param str insert_data_option: (optional) Determines how
the input data
should be inserted. See InsertDataOption_ in the Sheets API reference. :param str table_range: (optional) The A1 notation of a
range to search
for a logical table of data. Values are appended after the last row of the table. Examples: A1 or B2:D4
It seems to be a problem with gspread itself. I encountered this problem myself and according to this thread not only us. In this thread they suggest to add
value_input_option = 'USER_ENTERED'
(so that your code looks like this:
values = ['2021-08-11', '-', '-', 372, 373, 'Brayden', 'ChrisT', 'Chris', 'Dida', 'Darren', 'Ferdi', 'Bernard', 'Cal', 'Gavin', 'Conor']
ws.append_row(values, value_input_option = 'USER_ENTERED')
)
in order to remove that single quote. It worked for me and I hope that it works for you as well

return blank cell instead of 30/12/1899 error

I have 2 googlesheets array formula
one gives latest date from a range
=ArrayFormula(IFERROR(LARGE(((Stock!$J$2:$J$900000)*(-- (Stock!$H$2:$H$900000="study"))),1)))
the other one gives second latest date
=ArrayFormula(IFERROR(LARGE(((Stock!$J$2:$J$900000)*(--(Stock!$H$2:$H$900000="study"))),2)))
the formulas work well but when the reference cell is blank it gives 30/12/1899, I want to get blank cell
maybe,
IF(<your long formula>="30/12/1899", "", <your long formula>)
If you don't wan't to execute the same thing twice you could put your function in another cell, than something likes this:
IF(<other with function result>="30/12/1899", "", <other with function result>)
haven't tested it though.

Get form field format itext7

I am getting form fields from the PDF document but I did not see any method for getting form field format ForExample there are multiple text form fields in my document including Number field, Date field, Percentage field.
Is there any way to get field format type in itext7
#Uladzimir Asipchuk
/TU dictionary contains ToolTip value. Format value is contained in /AA >> /K dictionary in PDF structure. However I have extracted the JS Method after some tries and exploring the PDF structure through Pre-Flight. The following code snippet give the associated JSMethod if any:
PdfDictionary additionalActions = formField.GetAdditionalAction();
if (additionalActions != null)
{
PdfDictionary formatDictionary = additionalActions.GetAsDictionary(PdfName.K);
PdfString jsMethod = formatDictionary.GetAsString(PdfName.JS);
string fieldJsMethod = jsMethod.GetValue();
}
I created a pdf via Adobe (as you suggested) and I indeed was able to set the "format" of a text field as Date, Number, Percentage, Email,..
Then I opened the resultant pdf in RUPS (an utility program used to open the pdf's tree) and investigated it.
It turned out that Adobe sets the "format" which you want to get as a /TU value of the field's dictionary. For example, for Percentage it's percentfield and for Email - emailfield.
Now the only thing you need to find the "format" of your fieeld is to get the value of /TU entry of your field:
field.getValue().getPdfObject().get(PdfName.TU)

metafor package, rma.uni, mods, Model matrix contains character variables

I'm trying to run a meta-regression with MD's as dependent variable. I want to add a numeric moderator (year published) to the rma.uni function.
Formula so far:
metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Pain$Author, Pain$Year), weighted=TRUE, subset=(Pain$outcomegruppe=="9"), mods =("Pain$Year") )
I always get the error message:
Error in metafor::rma.uni(yi = MCID12, sei = SE12, method = "FE", data = Pain, :
Model matrix contains character variables.
My "Year" veriable is definetly numeric. As soon as I don't use the "mods" argument, everything works normal.
Could anyone help me with this problem?
Thanks in advance!
Don't put Year in quotes. Also, you don't need the Pain$ parts and weighted=TRUE is the default. This should do it:
metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Author, Year),
subset=(outcomegruppe=="9"), mods=~Year)

Get Month Name of java.time.chrono.HijrahDate instance

HijrahDate hd=HijrahChronology.INSTANCE.date(LocalDate.of(2014,11, 25));
If we have HijrahDate Instance , it is expected to have a method in UmalquraCalendar API that shows the name of month :
i inspect properties of this instance using groovy API :
['era':AH,
'class':class java.time.chrono.HijrahDate,
'prolepticMonth':17233,
'eraValue':1,
'dayOfWeek':2,
'leapYear':false,
'chronology':Hijrah-umalqura,
'dayOfYear':32]
However we don't find the month name which must be one of the following list items :
Muḥarram (محرم meaning "forbidden"), so called because battle was
forbidden (haram) during this month. Muharram includes the Day of
Ashura.
Ṣafar (صفر meaning "void"), supposedly named thus because
pagan Arab houses were empty this time of year while their occupants
gathered food.
Rabīʿ I (Rabīʿ al-Awwal, ربيع الأوّل) meaning "the
first spring".
Rabīʿ II (Rabīʿ ath-Thānī ربيع الثاني or Rabīʿ al-Ākhir
ربيع الآخ
.....................
............ so on SEE
Thus , since there is no attribute save month's name , it is expwcted to have a method retrieve this info ?
What's this method?
The date does not contain information about the names of the months or days. To get that you need a formatter:
System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd));
prints Safar.
Since the main language of UmalQura is the arabic langugage, Developers & programmers who uses UmalQuraCalender want to display the month in arabic. Thus , we base on #assylias answer we can add the Locale object to print صفر instead of Safar
System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd,new Locale("ar")));
public String getIslamicDate(){
return DateTimeFormatter.ofPattern("MMMM",new Locale("ar")).format(HijrahDate.now());
}
I think this should work just fine and return the month in arabic language

Resources