以前,我使用 ListFeed 访问 Google 电子表格并获取行。随着行数的增加,我需要转向 CellFeed 以便批量获取数据。
我在使用单元格 Feed 时遇到问题,即不返回 Google 电子表格中的 null 值或空值。而当我使用 ListFeed 时,它也常常返回空白值。
下面是一段代码:
URL cellFeedUrl2 = new URI(SPREADSHEET_FEED_URL.toString() + "?min-row=2&max-row=5").toURL();
CellFeed cellFeed2 = service.getFeed(cellFeedUrl2, CellFeed.class);
for (CellEntry cell : cellFeed2.getEntries()){
System.out.println(cell.getCell().getValue() + "\t");
}
实际输出:
1.第1行
姓名
电子邮件
出生日期
电话
2.第2行
姓名
电子邮件
电话
(没有 DOB,因为它在电子表格中为空,但仍然应该显示)
预期输出:
1.第1行
姓名
电子邮件
出生日期
电话
2.第2行
姓名
电子邮件
出生日期
电话
请推荐!
最佳答案
解决方案是在 URL 中添加一个额外的参数,如下所示:
URL cellFeedUrl2 = new URI(SPREADSHEET_FEED_URL.toString() + "?return-empty=true&min-row=2&max-row=5").toURL();
CellFeed cellFeed2 = service.getFeed(cellFeedUrl2, CellFeed.class);
for (CellEntry cell : cellFeed2.getEntries()){
System.out.println(cell.getCell().getValue() + "\t");
}
参数“return-empty=true”将空白值返回为null,因此如果发生异常,可以使用try-catch block 进行处理。
关于java - 如何让 Google Spreadsheet 的 "CellFeed"也返回空白单元格(使用 Java)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39408698/