Pregunta

I am using Google SpreadSheet API in Java to read and update a Spreadsheet. Let's say I have few columns named A and B.

A contains a formula.

B is pure text.

When I cycle through the SpreadSheet to update some specific rows:

URL listFeedUrl = new URI(worksheet.getListFeedUrl().toString() + "?sq=somefield=" + URLEncoder.encode("\"" + somevalue+ "\"").toString()).toURL();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

for (ListEntry row : listFeed.getEntries()) {
    if (something.compareTo(somethingelse) == 0) {
        row.getCustomElements().setValueLocal("B", request.getParameter("B"));
        row.update();
    }
}

The formula in the column A is lost. Only the result of the formula is kept. I guess it has something to do with the update() method but it looks like every row that I read looses the formula, not just the one where I am executing the update. What can I do in order to preserve the formula? I am not even reading/editing that cell... Thanks.

EDIT: As indicated in the documentation the list-based feed does not handle formulas but the thing is, I am not reading and/or modifying the cell that contains a formula...

¿Fue útil?

Solución

You could try saving the formula in an array first, then assigning it back to the sheet.

function myFunction() {
  sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  range = 'A1:A5';
  myFormulas = sheet.getRange(range).getFormulas();
  sheet.getRange(range).setFormulas(myFormulas);
 }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top