如何使用c#在电子表格google docs中编写单元格

时间:2012-03-15 11:40:39

标签: c# spreadsheet google-docs

现在我可以获得我想要的电子表格的所有信息,但现在我想更新一个单元格的内容,我不知道如何!我读到了api,但我找不到解决办法,你能帮帮我吗?

这是我获取所有信息的代码,我与您分享,也许它可以帮助任何人......

  DataTable dt = new DataTable();
        try
        {
            SpreadsheetsService service = new
SpreadsheetsService("ServiceName");
            service.setUserCredentials("login", "pass");
            SpreadsheetQuery query = new SpreadsheetQuery();
            query.Title = "DocumentName";
            SpreadsheetFeed feed = service.Query(query);
            if (feed.Entries.Count != 1) return;

            AtomLink link =
feed.Entries[0].Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel,
null);
            WorksheetQuery worksheetQuery = new
WorksheetQuery(link.HRef.ToString());
            worksheetQuery.Title = "SheetName";
            WorksheetFeed worksheetFeed =
service.Query(worksheetQuery);
            if (worksheetFeed.Entries.Count != 1) return;

            WorksheetEntry worksheet =
(WorksheetEntry)worksheetFeed.Entries[0];

            AtomLink listFeedLink =
worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

            ListQuery listQuery = new
ListQuery(listFeedLink.HRef.ToString());
            ListFeed listFeed = service.Query(listQuery);
            // define the table's schema
            dt.Columns.Add(new DataColumn("A", typeof(string)));
            dt.Columns.Add(new DataColumn("B", typeof(string)));
            dt.Columns.Add(new DataColumn("C", typeof(string)));
            dt.Columns.Add(new DataColumn("D", typeof(string)));
            foreach (ListEntry worksheetRow in listFeed.Entries)
            {
                string station = string.Empty;
                string scanData =
worksheetRow.Elements[0].Value.ToString();
                string scanData1 =
worksheetRow.Elements[1].Value.ToString();
                string scanData2 =
worksheetRow.Elements[2].Value.ToString();
                string scanData3 =
worksheetRow.Elements[2].Value.ToString();
                string[] arSD = new string[100];

                DataRow dr = dt.NewRow();
                dr["A"] = scanData;
                dr["B"] = scanData1;
                dr["C"] = scanData2;
                dr["D"] = scanData3;
                dt.Rows.Add(dr);

            }

            dgwTabla.DataSource = dt;

        }

        catch (Exception ex)
        {
        }

1 个答案:

答案 0 :(得分:2)

有一个完整的示例显示了如何在https://developers.google.com/google-apps/spreadsheets/#changing_contents_of_a_cell

中更改C#中的单元格内容