2017-06-02 84 views
0

的內容我已經使用https://developers.google.com/drive/v3/web/manage-downloads,我有一個代碼的工作副本,可以從Google驅動器下載具有權限訪問的文件。如何閱讀谷歌文檔

有什麼辦法,我可以閱讀Word文檔

示例代碼下載文件(使用的GDrive - 新建 - 新文件創建):

private static void DownloadFile(string fileId, DriveService driveService) 
{ 

    var request = driveService.Files.Export(fileId, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 
    var stream = new System.IO.MemoryStream(); 
    // Add a handler which will be notified on progress changes. 
    // It will notify on each chunk download and when the 
    // download is completed or failed. 
    request.MediaDownloader.ProgressChanged += 
      (IDownloadProgress progress) => 
      { 
       switch (progress.Status) 
       { 
        case DownloadStatus.Downloading: 
         { 
          Console.WriteLine(progress.BytesDownloaded); 
          break; 
         } 
        case DownloadStatus.Completed: 
         { 
          Console.WriteLine("Download complete."); 
          break; 
         } 
        case DownloadStatus.Failed: 
         { 
          Console.WriteLine("Download failed."); 
          break; 
         } 
       } 
      }; 


    request.Download(stream); 

    using (FileStream file = new FileStream("file.doc", FileMode.Create, FileAccess.Write)) 
    { 
     stream.WriteTo(file); 
    } 
} 

回答

0

如果它是一個真正的DOC文件,然後你可以得到使用

Code7248.word_reader

private string readFileContent(string pDocPath) 
{ 
    if(!System.IO.File.Exists(pDocPath)) 
    { 
     Console.WriteLine("The file doesn't exist"); 
     return String.Empty; 
    } 

    var extractor = new TextExtractor(pDocPath); 
    var txt = extractor.ExtractText(); 
    Console.WriteLine(txt); 
    return txt; 
} 

static void Main(string[] args) 
{  
    var strDocPath = @"C:\Temp\yourWordDoc.doc"; 
    var strDocTxt = readFileContent(strDocPath); 
} 
+0

感謝您的快速響應,但我想直接從驅動器中讀取文檔並下載它。 – user1621791

0

優米文唉想在谷歌驅動器用戶界面檢查這兩種方式來open files

開放與上下文菜單項

  • 呼叫files.get檢查用戶的權限爲一個文件,獲取元數據和下載文件內容。如果文件是使用Google Doc MIME類型創建的,請打開Goog​​le文檔並將其轉換爲支持的格式。

的谷歌選擇對話框打開文件

  • 應用程序可以顯示一個文件選擇從應用程序本身選擇的內容。有關更多詳細信息,請參閱files picker guide