【问题标题】:Add header via Google Spreadsheet API通过 Google 电子表格 API 添加标题
【发布时间】:2011-09-07 10:15:44
【问题描述】:

我无法通过 Java API 将标题(或任何常规数据)插入到新创建的工作表中。插入数据的标准方法是提供标题和值,例如

newEntry.getCustomElements().setValueLocal(header, value2);

这个问题类似于在stackoverflow上发布的这个问题:

How to add header in Google spreadsheet

建议的答案是尝试使用基于单元格的提要,而不是上面示例中的基于列表的提要。我一直无法执行此操作,因为对单元格的任何查询或获取单元格提要的尝试似乎都返回 0,因为任何单元格中都没有要返回的数据......至少这是我认为正在发生的事情......

例如

    public void getCells(){
         cellFeedUrl = worksheetEntry.getCellFeedUrl();
        CellFeed feed;
        try {
            feed = spreadSheetService.getFeed(cellFeedUrl, CellFeed.class);

        for (CellEntry cell : feed.getEntries()) {
          System.out.println(worksheetEntry.getTitle().getPlainText());
          String shortId = cell.getId().substring(cell.getId().lastIndexOf('/') + 1);
          System.out.println(" -- Cell(" + shortId + "/" + cell.getTitle().getPlainText()
              + ") formula(" + cell.getCell().getInputValue() + ") numeric("
              + cell.getCell().getNumericValue() + ") value("
              + cell.getCell().getValue() + ")");
        }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

and

public void queryHeader(){

    CellQuery query = new CellQuery(cellFeedUrl);
    query.setMinimumRow(1);
    query.setMaximumRow(1);
    query.setMinimumCol(1);
    query.setMaximumCol(1);
    try {
        CellFeed feed = spreadSheetService.query(query, CellFeed.class);

        List<CellEntry> entries = feed.getEntries();

        for(CellEntry cell : entries){

            cell.changeInputValueLocal("new");
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

【问题讨论】:

    标签: java google-sheets google-docs-api


    【解决方案1】:

    您对未返回的空单元格的怀疑是正确的。您可以通过添加以下行来覆盖此默认设置:

    query.setReturnEmpty(true);

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 1970-01-01
      • 2016-12-28
      • 2016-10-20
      • 1970-01-01
      • 2017-01-23
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多