0
votes

I am using the Google Sheets Java API to pull data from a spreadsheet, like so:

ValueRange valueRange = sheetsService.spreadsheets().values().get(docId, sheetName).execute();
List<List<Object>> rows = valueRange.getValues();

However, this spreadsheet contains formulas and I want the actual formula itself, not the calculated value of the formula.

How do I get the formula?

1

1 Answers

1
votes

You should use ValueRenderOptions in your query. This will allow you to get either the calculated value or the raw value.

Sheets sheetsService = createSheetsService();
Sheets.Spreadsheets.Values.Get request =
    sheetsService.spreadsheets().values().get(spreadsheetId, range);
request.setValueRenderOption(valueRenderOption);

ValueRange response = request.execute();

Have a look here for some Java examples: spreadsheets documentation