gpt4 book ai didi

java - Google Spreadsheet API - 找到列中的第一个空单元格?

转载 作者:搜寻专家 更新时间:2023-11-01 00:53:48 25 4
gpt4 key购买 nike

有没有一种好方法可以通过 Java 从 Google 的电子表格服务中获取列中的第一个空单元格?

我知道我可以使用:

public CellFeed CheckColumn(int row, int col) 
throws IOException, ServiceException {
CellQuery query = new CellQuery(cellFeedUrl);
query.setMinimumRow(row);
query.setMaximumRow(row);
query.setMinimumCol(col);
query.setMaximumCol(col);
query.setReturnEmpty(true);

CellFeed feed = service.query(query, CellFeed.class);
int cell_loc[];

for (CellEntry entry : feed.getEntries()) {
cell_loc=CheckIfEmpty(entry);
}
return cell_loc;
}

然后遍历条目,但我不想一次加载整个列,这对我的用户来说很慢,而且只遍历整个列似乎很糟糕

有什么想法吗?

最佳答案

这个小片段将使用 Google Apps 脚本在 Google 电子表格中创建一个函数:

function emptySpace(array) {
// set counter
var counter = 0;

// itterate through values
for (i in array){
if (array[i].length > 1) {
throw ("Only single column of data");
} else {
if(array[i][0] != "") {
counter++;
} else {
break;
}
}
}

// return value + 1
return counter + 1;
}

通过脚本编辑器将此脚本添加到您的电子表格,函数 emptySpace 在整个工作表中都可用,如下所示:=emptySpace(A1:A7)

查看我创建的示例文件:empty space

关于java - Google Spreadsheet API - 找到列中的第一个空单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/924339/

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