我正在使用.net(https://code.google.com/p/google-gdata/)的Google数据API来读取某些Google文档电子表格中的数据。
我发现在返回数据之前,从大型电子表格(> 14000条记录)中读取需要很长时间,几个小时。
我使用的代码如下,是否有其他方法可用于读取数据,或者我是否遗漏了其他内容以加快此过程?
public void ReadSpreadsheet(string applicationName, string title, string sheetName, string cellRange, string userName, string password)
{
var service = new SpreadsheetsService(applicationName);
service.setUserCredentials(userName, password);
SpreadsheetEntry spreadSheetEntry = GetSpreadsheetByTitle(service, title);
WorksheetEntry workSheetEntry = GetWorkSheetByTitle(spreadSheetEntry.Worksheets, sheetName);
AtomEntryCollection list = GetCells(service, workSheetEntry, cellRange);
}
public static SpreadsheetEntry GetSpreadsheetByTitle(SpreadsheetsService service, string title)
{
var query = new SpreadsheetQuery();
query.Title = title;
SpreadsheetFeed feed = service.Query(query);
return (from SpreadsheetEntry entry in feed.Entries
where title.Equals(entry.Title.Text, StringComparison.InvariantCultureIgnoreCase)
select (entry)).FirstOrDefault();
}
public static WorksheetEntry GetWorkSheetByTitle(WorksheetFeed feed, string title = null)
{
return (from WorksheetEntry entry in feed.Entries
where title != null && title.Equals(entry.Title.Text, StringComparison.InvariantCultureIgnoreCase)
select (entry)).FirstOrDefault();
}
public static AtomEntryCollection GetCells(SpreadsheetsService service, WorksheetEntry entry, string range)
{
AtomLink cellFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);
var query = new CellQuery(cellFeedLink.HRef.ToString());
query.Range = range;
query.ReturnEmpty = ReturnEmptyCells.yes;
// this line is what takes the most time
CellFeed feed = service.Query(query);
return (feed.Entries);
}