2012-06-13 7 views
1

에서 Excel 파일을 업로드하는 방법 C#을 사용하여 Google 문서에 Excel 파일을 업로드하고 싶습니다. 구문을 사용 노호 XLS 파일Google 문서

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

를 업로드하지만 내가이 conversion.I 그냥 내 구글 doc.Help 내 엑셀 파일을 업로드 할 싶지 않아 나누었다을 CSV로 업로드 파일 변환 후, 작동하지 않습니다 변환없이 엑셀 파일을 업로드 할 수 있습니다. 진보 된 감사의 말씀

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) 파일을 text/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

업로드 할 때 문서가 변환되지 않도록하려면 업로드 uri에? convert = false를 추가해야합니다.