在Google Spreadsheet API中添加一个简单的标题行

Vac*_*cca 3 c# google-spreadsheet-api

如何通过Google Spreadsheet API在programmaticaly创建的工作表上添加简单的标题行?很难理解他们的doc,它只提到了如何在已经创建的标题行上添加一行.如果首次使用基于单元格的Feed添加标题行,

// 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();
    }
  }
Run Code Online (Sandbox Code Playgroud)

此代码不能用作cellFeed.Entries为0,因此控件不会进入for循环.我已经添加了一个包含(4)行和(10)列的工作表.但是,如何首先输入一个简单的标题行(作为列),然后输入其他行(作为这些列中的值)?我知道已经提出的问题很少,但没有人提出答案,这是如此令人沮丧和难以理解这个API实施起来如此复杂?

Vac*_*cca 5

答案是 :

        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);
Run Code Online (Sandbox Code Playgroud)

然后可以根据与上述标题行匹配的文档在下面添加行.