1

使用 C#,想在 google doc 上上传 excel 文件。下面的语法用于上传 xls 文件

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

但它不工作,上传文件转换为 csv 后。但我不想要这种转换。我只想在我的谷歌文档中上传我的 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());
4

2 回答 2

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"); 

这是我使用的 wikipedia/google 搜索:

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

于 2012-06-13T14:28:32.740 回答
0

为确保文件在上传时不会被转换,您还应该附加?convert=false到上传 uri。

于 2012-07-12T10:02:01.280 回答