繁体   English   中英

如何上传Excel文件并将其以编程方式转换为Google电子表格?

[英]How to Upload Excel file and convert that to Google spreadsheet programmatically?

我正在编写桌面程序以与Google spreadsheets进行交互,为此,我需要上传excel sheet并通过编程方式将其转换为Google spreadsheet 我检查了Google驱动器,但Google电子表格API找不到执行此操作的方法。 如果有人可以提出任何建议的方法,那将是极大的帮助。

这是我现在拥有的代码,可以正确上传excel文件,但不会转换为Google电子表格。

            Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
            body.Title = "My document";
            body.Description = "A test document";
            body.MimeType = "application/vnd.ms-excel";

            byte[] byteArray = System.IO.File.ReadAllBytes("test.xlsx");
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

            FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "application/vnd.google-apps.spreadsheet");
            request.Convert = true;
            request.Upload();

            Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
            Console.WriteLine("File id: " + file.Id);
            Console.WriteLine("Press Enter to end this process.");
            Console.ReadLine();

我使用了Drive API,下面是我用来转换XLS文件的代码段

function convert(xlsxFileId, name) { 
  var xlsxBlob = xlsxFileId;
  var file = {
    title: name,
    //Which Drive Folder do you want the file to be placed in
    parents: [{'id':'FOLDER_ID'}],
    key: 'XXXX',
    value: 'XXXX',
    visibility: 'PRIVATE'
  };

  file = Drive.Files.insert(file, xlsxBlob, {
    convert: true
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM