简体   繁体   English

将Google Spreadsheet API与JAVA结合使用时,引用中的公式单元格值未更新

[英]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与Jav​​a集成。

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.

相关问题 Google Java电子表格API,使用单元格网址更新单元格 - Google java spreadsheet API, update cell using the cell url 如何使用Java和Google Spreadsheet API获取Google电子表格中单元格的内容 - How to get the contents of a cell in a google spreadsheet using java and Google Spreadsheet API 使用Google Spreadsheet API在Google中的Google驱动器中创建电子表格 - Create Spreadsheet using Google Spreadsheet API in Google drive in Java 在Java中使用Google电子表格api创建Google电子表格 - creating a google spreadsheet using google spreadsheet api in java 使用带有Java的API在Google电子表格中插入一行 - insert a row in to a google spreadsheet using the API with java Java Google SpreadSheet API,如何更新单元格以添加注释? - Java Google SpreadSheet API, how to update cell to add a note? 使用 JAVA 表格 API 识别谷歌表格中的单元格类型(公式、列表等) - Identify cell type (formula, list etc') in google sheet using JAVA sheets API 如何使用Google Spreadsheet API将一个单元格的样式复制到另一个单元格中 - How to copy styles of a cell into another one using Google Spreadsheet API Java | 如何使用API​​在Google电子表格范围内查找值(行和列号)? - Java | How to find a value (row and column number) in range of google spreadsheet using API? 使用 Google API Java 客户端将数据库上传到 Google 电子表格 - Using Google API Java Client for Uploading Database to Google Spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM