kra*_*yal 5 java google-sheets google-apps-script
有没有一种很好的方法可以通过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;
}
Run Code Online (Sandbox Code Playgroud)
并浏览条目,但我不想一次加载整个列,这对我的用户来说很慢,而且只是遍历整个列似乎很糟糕
有什么想法吗?
这个小片段将使用 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;
}
Run Code Online (Sandbox Code Playgroud)
通过脚本编辑器将此脚本添加到电子表格中,并且在整个工作表中都可以使用函数emptySpace,如下所示:=emptySpace(A1:A7)
。
请参阅我创建的示例文件:空白空间
归档时间: |
|
查看次数: |
4635 次 |
最近记录: |