2012-08-15 71 views
3

我想寫在谷歌電子表格使用C#中的特定單元格,而不必搜索每一個單元格,看看它是否是正確的單元格。例如,我不想搜索「A1」是否在工作表中的所有單元格的標題中,以便寫入A1。在其他編程語言(python)中,我找到了很多關於如何執行此操作的示例,但在C#中找不到相同的方法。我怎麼可以這樣做:c#谷歌spreadhseets輸入到一個特定的單元格

cell[1,1].value = "JoMama"; 
+0

是否使用發現這裏的.NET庫? http://code.google.com/p/google-gdata/ – dana 2012-08-16 20:54:28

+1

是的,我正在使用它。我終於找到了答案。我想你必須設置最小和最大的列和CellQuery的行是相同的,所以CellFeed.Entries數組只有一個成員。然後你只需訪問該成員。 (請參閱下面的代碼) – carlilelance 2012-08-16 22:10:03

回答

4
/// <summary> 
    /// Updates a single cell in the specified worksheet. 
    /// </summary> 
    /// <param name="service">an authenticated SpreadsheetsService object</param> 
    /// <param name="entry">the worksheet to update</param> 
    private static void UpdateCell(SpreadsheetsService service, WorksheetEntry entry) 
    { 
     AtomLink cellFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null); 
     CellQuery query = new CellQuery(cellFeedLink.HRef.ToString()); 
     Console.WriteLine(); 

     Console.Write("Row of cell to update? "); 
     string row = Console.ReadLine(); 

     Console.Write("Column of cell to update? "); 
     string column = Console.ReadLine(); 

     query.MinimumRow = query.MaximumRow = uint.Parse(row); 
     query.MinimumColumn = query.MaximumColumn = uint.Parse(column); 

     CellFeed feed = service.Query(query); 
     CellEntry cell = feed.Entries[0] as CellEntry; 

     Console.WriteLine(); 
     Console.WriteLine("Current cell value: {0}", cell.Cell.Value); 
     Console.Write("Enter a new value: "); 
     string newValue = Console.ReadLine(); 

     cell.Cell.InputValue = newValue; 
     AtomEntry updatedCell = cell.Update(); 

     Console.WriteLine("Successfully updated cell: {0}", updatedCell.Content.Content); 
    } 
+0

http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/spreadsheets/spreadsheetdemo.cs – carlilelance 2012-08-16 22:33:05