[我想做的是将Google表格导出为PDF,而不显示网格线。我在网上看到代码样例,说明如何使用类似url的方式访问该参数:
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
"?format=pdf&"+
"size=0&"+
"fzr=true&"+
"portrait=false&"+
"fitw=true&"+
"gridlines=false&"+
"printtitle=true&"+
"sheetnames=true&"+
"pagenum=CENTER&"+
"attachment=true";
但是我正在使用以下代码,该代码未利用网址:
private static void DownloadfileFromGDrive(DriveService service, string fileId, string filePath)
{
var request = service.Files.Export(fileId, "application/pdf");
using (var memoryStream = new MemoryStream())
{
request.MediaDownloader.ProgressChanged += (IDownloadProgress progress) =>
{
switch (progress.Status)
{
case DownloadStatus.Downloading:
Debug.WriteLine(progress.BytesDownloaded);
break;
case DownloadStatus.Completed:
Debug.WriteLine("Download Complete");
break;
case DownloadStatus.Failed:
Debug.WriteLine("Download Failed");
break;
}
};
request.Download(memoryStream);
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
fileStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length);
};
}
}
如何从代码中访问这些参数?
这个答案怎么样?
不幸的是,当使用用于导出为PDF格式的查询参数时,service.Files.Export(fileId, "application/pdf")
无法用于这种情况。在这种情况下,需要使用访问令牌下载PDF文件。这种情况的终结点如下。
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
"?format=pdf&"+
"size=0&"+
"fzr=true&"+
"portrait=false&"+
"fitw=true&"+
"gridlines=false&"+
"printtitle=true&"+
"sheetnames=true&"+
"pagenum=CENTER&"+
"attachment=true&"+
"access_token=###"; // Added
如果这不是您想要的方向,我很抱歉。