【问题标题】:Google Spreadsheet API - find the first empty cell in a column?Google Spreadsheet API - 找到列中的第一个空单元格?
【发布时间】:2009-05-29 04:05:30
【问题描述】:

有没有一种好的方法可以通过 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;
}

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

有什么想法吗?

【问题讨论】:

  • @Jacob 问题是关于 Java 而不是 Google Apps 脚本。

标签: java google-sheets google-sheets-api


【解决方案1】:

这个小 sn-p 将使用 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 Apps 脚本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
相关资源
最近更新 更多