开发者

Add header via Google Spreadsheet API

I am unable to insert a header (or any regular data) into a newly created worksheet via Java API. The standard way to insert data is to provide a header and value e.g

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

This question similar to this one posted on stackoverflow:

How to add header in Google spreadsheet

The suggested answer was to try use cell based feed as opposed to list based in example above. I have been unable to do this as any query on cells or attempts at getting the cell feed seem to return 0 as there is no data in any cell to return...at least this is what I think is happening...

e.g.

    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.get开发者_Go百科Id().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();
    }
}


Your suspicion about the empty cells not being return is correct. You can override this default setting by adding the following line:

query.setReturnEmpty(true);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜