这是我认为我们甚至可以接近电子表格 API 的唯一方法。这不是完整的代码,它在我编写的函数中,但你明白了......它在 C# 中:
使用示例:
--row 1 = header row
--row 2 = data
--row 3 = data
--row 4 = totally blank
--row 5 = data
--row 6-100 = totally blank
用英语讲:
获取工作表的 ListFeed.Entries.Count。ListFeeds 忽略标题行,因此在此示例中计数为“2”。
获取工作表的 CellFeed 以循环浏览单元格。CellFeeds DO 包括标题行作为第 1 行,因此在示例中,从 CellFeed 的角度来看,第一个空白行必须是第 4 行(标题=1,然后是 2 个数据行,然后是终止 ListFeed 集的第一个空白行) ,因此我们应该开始在第 5 行及以后的单元格中查找任何非空的单元格:
foreach (WorksheetEntry entry in wsFeed.Entries)
{
//Get the worksheet CellFeed:
CellQuery cellQuery = new CellQuery(entry.CellFeedLink);
CellFeed cellFeed = service.Query(cellQuery);
//Get the worksheet ListFeed to compare with the CellFeed:
AtomLink listFeedLink = entry.Links.FindService(
GDataSpreadsheetsNameTable.ListRel, null
);
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
//need to have service object already created for this... see API docs
ListFeed listFeed = service.Query(listQuery);
//Now to check if there is data after the ListFeed
//set which would indicate a blank line in the data set (not allowed)
foreach (CellEntry cell in cellFeed.Entries)
{
//start looking in cells in the row after what would be the first blank row
if (cell.Row > listFeed.Entries.Count + 2)
{
if (cell.Value != "")
{
MessageBox.Show("ERROR: There appears to be a blank row +
in the middle of the data set in worksheet: " +
entry.Title.Text + ". Completely blank rows " +
"are not allowed in between data rows. Each row " +
"within the data set must have at least one " +
"value in at least one cell. There CAN and " +
"should be blank rows after the data set at " +
"the bottom of the worksheet.");
return false;
}
}
}
}