【问题标题】:Spreadsheet API : Get cell entry from specific cell address电子表格 API:从特定单元格地址获取单元格条目
【发布时间】:2015-09-01 11:38:32
【问题描述】:

如何在给定特定单元格地址的情况下获得CellEntry,例如A1 表示法。例如,

String address = "A1";
CellEntry cellEntry = getCellEntry(address);

public CellEntry getCellEntry(String address){

    //- What can I do inside here

}

以前,我使用CellFeed 获取所有内容并使用cellFeed.getEntries 进行迭代以获取每个 CellEntry 并根据单元地址过滤掉。但我认为它会有性能问题,因为我的电子表格很大。任何的想法 ?我正在使用 Java。

【问题讨论】:

    标签: java google-spreadsheet-api


    【解决方案1】:

    我想我在这里有两种方法:

    方法一

    使用CellQuery

    public CellEntry getCellEntry(URL cellFeedUrl, Integer colNum, Integer rowNum){
    
        CellQuery cellQuery = new CellQuery(cellFeedUrl);
        cellQuery.setMaximumCol(colNum);
        cellQuery.setMinimumCol(colNum);
        cellQuery.setMaximumRow(rowNum);
        cellQuery.setMinimumRow(rowNum);
    
        CellFeed cellFeed = service.getFeed(cellQuery, CellFeed.class)              
        return cellFeed.getEntries().get(0);
    }
    

    注意:setMaximumColsetMinimumCol 必须相同才能获取指定的列。与setMaximumRowsetMinimumRow 类似。

    方法二

    使用CellFeedURL

    public CellEntry getCellEntry(WorksheetEntry worksheet, Integer colNum, Integer rowNum){
    
        if (colNum == null || rowNum == null){
            //- do something
        }
        else {
    
            String row = "?min-row=" + rowNum + "&max-row=" + rowNum;
            String col = "&min-col=" + colNum + "&max-col=" + colNum;
    
            URL cellFeedUrl = new URI(worksheet.getCellFeedUrl().toString()
            + row + col).toURL();
            CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
            return cellFeed.getEntries().get(0);
        }
    }
    

    注意:基于Google Spreadsheet API : Changing content of a cell

    我个人认为第二种方法更好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      相关资源
      最近更新 更多