C# 在Google电子表格API中添加一个简单的标题行
如何通过Google电子表格API在programmaticaly创建的工作表上添加简单的标题行?很难理解他们的文档,它只提到了如何在已经创建的标题行上添加一行。如果首次使用基于单元格的提要添加标题行C# 在Google电子表格API中添加一个简单的标题行,c#,google-spreadsheet-api,C#,Google Spreadsheet Api,如何通过Google电子表格API在programmaticaly创建的工作表上添加简单的标题行?很难理解他们的文档,它只提到了如何在已经创建的标题行上添加一行。如果首次使用基于单元格的提要添加标题行 // Fetch the cell feed of the worksheet. CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink); CellFeed cellFeed = service.Query(cellQuery
// Fetch the cell feed of the worksheet.
CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
CellFeed cellFeed = service.Query(cellQuery);
// Iterate through each cell, updating its value if necessary.
foreach (CellEntry cell in cellFeed.Entries)
{
if (cell.Title.Text == "A1")
{
cell.InputValue = "name";
cell.Update();
}
else if (cell.Title.Text == "B1")
{
cell.InputValue = "age";
cell.Update();
}
}
此代码不作为cellFeed使用。条目为0,因此控件永远不会进入for循环。
我已经添加了一个包含(4)行和(10)列的工作表。但是,如何首先输入一个简单的标题行(作为列),然后输入其他行(作为这些列中的值)?
我知道已经提出了几个问题,但没有一个有答案,这是如此令人沮丧和难以理解的API是什么,如此复杂的实现?答案是:
CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
CellFeed cellFeed = _SpService.Query(cellQuery);
CellEntry cellEntry = new CellEntry(1, 1, "name");
cellFeed.Insert(cellEntry);
cellEntry = new CellEntry(1, 2, "age");
cellFeed.Insert(cellEntry);
cellEntry = new CellEntry(1, 3, "address");
cellFeed.Insert(cellEntry);
然后可以根据与上面标题行匹配的单据在下面添加行。单元格查询默认不返回空单元格。 您需要覆盖此设置 按如下方式编辑代码:
CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
cellQuery.ReturnEmpty = ReturnEmptyCells.yes;
CellFeed cellFeed = _SpService.Query(cellQuery);
您使用什么代码创建工作表?我正在创建一个工作表,我可以看到它添加到电子表格中,但我仍然无法获得cellfeedlink。。我甚至还试图再次从电子表格对象中读取工作表提要。刚刚收到。显然,service.Insert(worksheetFeed,worksheetEntry)返回一个worksheetEntry对象。。因此,如果您保存它,基本上就像更新工作表以包含所有feedlinks/uri/id,等等。。