[英]Formula Cell value is not updating in the reference while Using Google Spreadsheet API with JAVA
I have this sample code in which I am trying to integrate google spreadsheet API with java. 我有此示例代码,其中我试图将Google电子表格API与Java集成。
import java.net.URL;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.CellEntry;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.WorksheetEntry;
public class ExpressionExample {
public static final String GOOGLE_ACCOUNT_USERNAME = "xxxx@gmail.com";
public static final String GOOGLE_ACCOUNT_PASSWORD = "xxx";
private static URL cellFeedUrl;
public static final String SPREADSHEET_URL = "https://spreadsheets.google.com/feeds/spreadsheets/1QWX-zOkBe36M7oC9sn6z8ZuccGt7Wg-IFwtynn379kM";
public static void main(String[] args) throws Exception {
SpreadsheetService service = new SpreadsheetService(
"Print Google Spreadsheet Demo");
service.setUserCredentials(GOOGLE_ACCOUNT_USERNAME,
GOOGLE_ACCOUNT_PASSWORD);
URL metafeedUrl = new URL(SPREADSHEET_URL);
SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl,
SpreadsheetEntry.class);
WorksheetEntry sheet = ((WorksheetEntry) spreadsheet.getWorksheets()
.get(0));
cellFeedUrl = spreadsheet.getWorksheets().get(0).getCellFeedUrl();
CellEntry cellA1 = new CellEntry(1, 1, "3");
CellEntry cellB1 = new CellEntry(1, 2, "high mech");
String line = "=IF(A1<5,IF(B1={\"high mech\",\"low mech\",\"mid mech\"},10,IF(B1=\"electronic\",20,0)),IF(A1>=5,IF(B1=\"electronic\",40,0),0)) ";
CellEntry cellc1 = new CellEntry(1, 3, line);
service.insert(cellFeedUrl, cellA1);
service.insert(cellFeedUrl, cellB1);
service.insert(cellFeedUrl, cellc1);
System.out.println(cellc1.getCell().getValue());
System.out.println(cellc1.getCell().getNumericValue());
System.out.println(cellc1.getCell().getDoubleValue());
}
}
When I am running the code I am getting this value. 当我运行代码时,我得到了这个值。
null null NaN 无无
I want the value of cell C1. 我想要单元格C1的值。 it is showing the correct value in google spreadsheet. 它在google电子表格中显示正确的值。 I am not able to read it in my code. 我无法在我的代码中阅读它。
Any help will be appreciated. 任何帮助将不胜感激。
getCell()
only reads the local information about the cell, ie the stuff you inserted. getCell()
仅读取有关单元的本地信息,即您插入的内容。 You'll have to get the cell again from a CellFeed
, then go through the entries to find you cell again to read back the online information. 您必须再次从CellFeed
获取该单元,然后遍历条目以再次找到您的单元以读回在线信息。
service.getFeed(cellFeedUrl, CellFeed.class);
for(CellEntry ce : cellFeed.getEntries()) {
Cell cell = ce.getCell();
if(cell.getRow() == 1 && cell.getCol() == 3) {
System.out.println(cell.getDoubleValue());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.