1
現在我可以得到我想要的所有電子表格的信息,但現在我想更新單元格的內容,我不知道如何!我閱讀了api的內容,但找不到解決方案,請問您能幫助我嗎?如何在電子表格中編寫單元格與谷歌文檔與C#
這是我的代碼來獲取所有的信息,我跟大家分享,也許它可以幫助任何人......
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)
{
}
你應該真的刪除忽略所有異常的大try/catch塊。 – xsl 2012-03-15 11:53:17