gpt4 book ai didi

java - 电子表格API : Get cell entry from specific cell address

转载 作者:太空宇宙 更新时间:2023-11-04 13:29:30 25 4
gpt4 key购买 nike

如何获取给定特定单元格地址的 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。

最佳答案

我想我这里有两种方法:

方法一

使用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 类似。

方法2

使用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

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

关于java - 电子表格API : Get cell entry from specific cell address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32330646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com