2

我正在使用适用于 .net 的 Google Data API ( https://code.google.com/p/google-gdata/ ) 从一些 Google Docs 电子表格中读取数据。

我发现从大型电子表格(> 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);
}
4

0 回答 0