簡體   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