2012-06-13 85 views
1

使用C#,希望在google doc上載excel文件。波紋管的語法使用上載xls文件如何在谷歌文檔中上傳excel文件

//use Content-Type: text/csv 
    entry.MediaSource = new MediaFileSource("E:\\Emailcontent.xls", "text/csv"); 

,但它不工作,上傳文件轉換後到csv。但我不希望這conversion.I只是想上傳我的Excel文件在我的谷歌doc.Help我要上傳excel文件與轉換。感謝先進的

string USERNAME = "[email protected]"; 
      string PASSWORD = "xxxxx"; 

      // Start the service and set credentials 
      DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1"); 
      service.setUserCredentials(USERNAME, PASSWORD); 
      Authenticator authenticator = new ClientLoginAuthenticator("TestApi", Google.GData.Client.ServiceNames.Documents, service.Credentials); 
      DocumentEntry entry = new DocumentEntry(); 
      // Set the document title 
      entry.Title.Text = "Legal Contract"; 
      entry.IsSpreadsheet = true; 
      // Set the media source 
      //entry.MediaSource = new MediaFileSource("E:\\New Microsoft Office Word Document.doc", "application/msword"); 
      entry.MediaSource = new MediaFileSource("E:\\Emailcontent.xls", "text/csv"); 
      // Define the resumable upload link 
      Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); 
      AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri); 
      link.Rel = ResumableUploader.CreateMediaRelation; 
      entry.Links.Add(link); 

      // Set the service to be used to parse the returned entry 
      entry.Service = service; 

      // Instantiate the ResumableUploader component. 
      ResumableUploader uploader = new ResumableUploader(); 

      // Set the handlers for the completion and progress events 
      uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone); 
      uploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(OnProgress); 

      // Start the upload process 
      uploader.InsertAsync(authenticator, entry, new object()); 
+0

將來,我會建議在發佈問題前先閱讀api。我明白,有時候很容易陷入困境並尋找錯誤的解決方案,但通過在發佈之前進行一些調查,這很容易解決。它肯定會讓你省點頭痛! :) – Tom

回答

2

您正在傳遞一個xls(Excel)文件作爲文本/ csv。如果你要上傳的XLS,使用

entry.MediaSource = new MediaFileSource("E:\\Emailcontent.xls", "text/csv");  

如果你要上傳的XLS,使用

entry.MediaSource = new MediaFileSource("E:\\Emailcontent.xls", "application/vnd.ms-excel"); 

這裏是維基百科/谷歌搜索,我用:

http://en.wikipedia.org/wiki/Internet_media_type

+0

非常感謝 – shamim

0

爲了確保文檔在上傳時不被轉換,您還應該在轉換後附加?convert = false uri