使用C#,想在google doc上上传excel文件。下面的语法用于上传xls文件
//use Content-Type: text/csv
entry.MediaSource = new MediaFileSource("E:\\Emailcontent.xls", "text/csv");
但是上传文件转换为csv后它无法正常工作。但我不想进行此转换。我只想在google doc上传我的excel文件。帮我上传excel文件,不用转换。谢谢高级
string USERNAME = "xxx@gmail.com";
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 :(得分: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");
以下是我使用的维基百科/谷歌搜索:
答案 1 :(得分:0)
为确保您在上传文档时不会转换文档,您还应将?convert=false
附加到上传文件中。