Google Sheet API 4: How to return cell string value with leading single quotes as-is? - google-sheets-api

Having a cell in Google Sheets with a value of '0123 and fetching it via the API it returns 0123 and omits the leading single quote.
Tried to use any of the available ValueRenderOption but always returns the cell value without single quote.
I would expect to get the single quote using the UNFORMATTED_VALUE or FORMULA value, but this is not the case.
Therefore: How to get the raw cell value, including leading single quotes?

I think this would be an expected behavior given the fact that the feature just makes the system recognize the values after the apostrophe as text, so it is more like the cell formatting feature rather than an actual formula but without changing the format of the whole cell and just the values next to the apostrophe.
After making some testing in the API explorer from the Google Sheets API I found out that if you remove the apostrophe the API will definitely recognize the values as numbers when using either UNFORMATTED_VALUE or FORMULA in the ValueRenderOption parameter, so the API will return number values in the response, however if you do it using '0123, what you get in the response instead of numbers is text (see screenshots below).
Number value
Text value
With all this we can determine that this would be expected and that adding the apostrophe symbol is an exception to the ValueRenderOption parameter due to how the API works. I have also submitted feedback in the documentation page to see of Google can add this information to the documentation since there is no mention of this in that page.
References:
Using Apostrophe to Add Leading Zero
Format numbers in a spreadsheet

Related

How to retrieve specific column value in string format through google sheets API?

We have multiple columns in our google excel sheet as below,
image1
We are trying following API call,
https://sheets.googleapis.com/v4/spreadsheets/7dj1kU54fgrhQk46uMrqq-W-QMlBq45kjiuEdhfjm5zE5gNvUoLk/values/'sheet1'!A2:O200?dateTimeRenderOption=SERIAL_NUMBER&valueRenderOption=UNFORMATTED_VALUE&majorDimension=ROWS
By hitting the above call, we get the output as below,
image2
But, we want the value of column Currency same as available in the sheet. That is $667 where as we just get 667 by the above API call.
If we just replace the value of valueRenderOption with FORMATTED_VALUE, we get the output as below,
image3
But, then it returns the value of all columns as formatted. We just want to get the value particular column as FORMATTED_VALUE. Is there any by which we can do this?
Unfortunately not - you need to make two API calls if you want different cells to have different ValueRenderOptions. This is a limitation of the API itself, as the specified ValueRenderOption must be the same for the whole range in a single call.

API coingecko data - doNotDelete

I use Coingecko's importJSON code to load data into a Google Sheet. The last parameter of the url (see below) is called 'doNotDelete!$A$!'. If I run the importJSON function in my sheet a numeric value in cell A1 of the tab doNotDelete shows up. What does this number mean? Is it the number of seconds that past since last execution? There is no explanation about it in the Coingecko's article about their API ImportJSON function for Google Sheets.
=ImportJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=2&sparkline=false","/name,/current_price,/market_cap,/price_change,/total_volume,/high_24h,/low_24h","noTruncate,noHeaders",doNotDelete!$A$1)
When the value of this cell changes ImportJSON gets updated values from the API. It doesn't have any meaningful value, your autorefresh script should change that to a random value whenever it is run.
It's not coingecko's script, it is from here and it is currently unmaintained, so if google changes the behavior of any of the used functions it can stop working.

Google Script Sheets API - default number format

It looks like google sheets is making the same mistake as Excel, by "thinking ahead" and converting the value "1.1.1" to 2001.01.01 when doing sheet.appendRow. I have tried to set the number format of the column in charge to "#" (which should be plain text) before inserting rows - but looks ineffective. On the other hand doing the same after inserts is also ineffective, as the content is already "date".
Adding ' before is working, but it is not what I need.
Is there any way to give a default format or to disable such automatic conversion (from google script)?
I have a cell in which a form deposits a variable number of values seperated by a comma such as: " 1, 2, 4, 6 " etc - when there are only three answers, Google "helps" me by converting the value into a date object. But it's supposed to be a list of choices...
It's not pretty, but I've managed a workaround by using .getDisplayValue instead of .getValue - it does change the cell value into a string, so if you need to do further manipulations that are dependent on the value being a number or something, obviously, this fails.
I overwrite the value for the problem cell in my array before passing it to .appendRow
//getting the values
var values = s.getRange(row,1,1,lastCol).getValues()[0];
//brute force crushing of problem value
values[5] = s.getRange(row,6).getDisplayValue();

EXCEL VBA: ConvertFormula returns #VALUE

I have several subroutines that use the ConvertFormula VBA command. Unfortunately I ran into a situation where none of the subroutines work. It appears it is the single line containing the ConvertFormula command that is returning the #VALUE error so I can't error check any deeper than that.
Using the Immediate window I was able to test this isolated command. Here are 3 separately executed lines of code.
ActiveSheet.range("Z270")=application.ConvertFormula(formula:="=Sheet2!V23+Sheet2!W23*Z$224+Sheet2!X23*Z$224^2+Sheet2!Y23*Z$224^3+Sheet2!Z23*Z$224^4",fromreferencestyle:=xlA1, toreferencestyle:=xla1, toabsolute:=xlabsolute)
ActiveSheet.range("Z270")=application.ConvertFormula(formula:="=Sheet2!V23+Sheet2!W23*Z$224+Sheet2!X23*Z$224^2+Sheet2!Y23*Z$224^3",fromreferencestyle:=xlA1, toreferencestyle:=xla1, toabsolute:=xlabsolute)
ActiveSheet.range("Z270")=application.ConvertFormula(formula:="=Sheeet2!V23+Sheeet2!W23*Z$224+Sheeet2!X23*Z$224^2+Sheeet2!Y23*Z$224^3",fromreferencestyle:=xlA1, toreferencestyle:=xla1, toabsolute:=xlabsolute)
The first line returned #VALUE, the 2nd returned the formula correctly, and the 3rd returned #VALUE  again. Notice that in the 3rd I'd renamed the offsheet reference to Sheeet2, with an extra 'e' to add length to the formula.
I suspect that the behavior is related only to the formula string length and not the contents. The formula string lengths in my example are 85, 66, and 70 characters for the 1st, 2nd and 3rd lines respectively.
I'm not sure where the exact cut-off is, or whether the $ is excluded from the character count limit. Just wanted to put this out there to see if anyone can confirm my hypothesis, provide further insight, or provide an alternative explanation.
In response to the RFI about reference cell values, all referenced cells contained numeric values. 'Z$224' value was 65, formatted as 65.0. Sheet2 cells V23 thru Z23 had the following values (formatted in scientific notation):
1.0037243; -0.000062039288; 0.000000012983893; -0.00000000042225392
Ran into the same with varying character limits. Have not found a fix but there are workarounds.
Shorten the formulas using Custom user functions
Write your own conversion function. Which you can use Regular Expression to insert dollar signs to references and simple Replace() to remove them.

How to format data copied from the Web and pasted into an Excel sheet without altering the string itself?

Let us say I need to copy a list of names from a webpage. Since I don't want to retain the formatting that is there in the webpage, I currently use Paste Special→"Match Destination format". This is simple and clean.
But Excel also removes any extra spaces present within the string.
e.g. ABC DEF will become ABC DEF.
This is also true for leading and trailing spaces. I believe this is the TRIM function at work which is part of the default settings.
What can I do to apply new formatting without applying the TRIM function? (Other than pasting with source formatting and changing the format manually?)
I think the question can be extended to other parts of the default settings. e.g. the default number formatting in Excel may not be what you want. I looked at the settings under Excel→Options but could not find the settings that specified number/text formatting.
Try to set that column formatting as Text (Manually) and performing Paste Special Values will consider the value as Text without changing anything in the pasted data.