【发布时间】:2017-08-21 22:40:20
【问题描述】:
任何人分享将docx,xlsx,pptx以编程方式转换为google格式的方法。我正在通过 Google Drive API 上传并使用 c# 分享给用户。每次有人编辑文件时都会创建一个重复的文件。
我想在上传时转换文件。所以我可以把转换后的文件分享给大家。
我正在使用 Google Drive v3 api。
下载代码:
private static System.IO.MemoryStream DownloadFile(DriveService service, string fileID)
{
var request = service.Files.Get(fileID);
var stream = new System.IO.MemoryStream();
// Add a handler which will be notified on progress changes.
// It will notify on each chunk download and when the
// download is completed or failed.
request.MediaDownloader.ProgressChanged += (Google.Apis.Download.IDownloadProgress progress) =>
{
switch (progress.Status)
{
case Google.Apis.Download.DownloadStatus.Downloading:
{
Console.WriteLine(progress.BytesDownloaded);
break;
}
case Google.Apis.Download.DownloadStatus.Completed:
{
Console.WriteLine("Download complete.");
//SaveStream(stream, saveTo);
break;
}
case Google.Apis.Download.DownloadStatus.Failed:
{
Console.WriteLine("Download failed.");
break;
}
}
};
request.Download(stream);
return stream;
}
private static void SaveStream(System.IO.MemoryStream stream, string saveTo)
{
using (System.IO.FileStream file = new System.IO.FileStream(saveTo, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
stream.WriteTo(file);
}
}
【问题讨论】:
标签: c# google-drive-api google-docs