一個谷歌帳戶,這是我到目前爲止有:下載所有電子表格到Excel中使用C#
// calls a new service and authenticate
SpreadsheetsService myService = new SpreadsheetsService("MyDownloader");
myService.setUserCredentials(DownloaderSettings.Default.Username,
DownloaderSettings.Default.Password);
// get a list of spreadsheets
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = myService.Query(query);
// download them all
foreach (SpreadsheetEntry entry in feed.Entries)
{
string key = entry.AlternateUri
.Content
.Substring(entry.AlternateUri.Content.IndexOf("?key="));
string dlUrl = "https://docs.google.com/feeds/download/spreadsheets/Export"
+ key
+ "&exportFormat=" + DownloaderSettings.Default.FileFormat
+ "&format=" + DownloaderSettings.Default.FileFormat;
Stream stream = myService.Query(new Uri(dlUrl));
using (FileStream fstream = new FileStream(entry.Title.ToString() + "."
+ DownloaderSettings.Default.FileFormat),
FileMode.Create,
FileAccess.ReadWrite,
FileShare.ReadWrite))
{
stream.CopyTo(fstream);
fstream.Flush();
}
}
我想所有的電子表格列表在我的帳戶,並將它們全部下載到xlsx
。我的帳戶中有大約10個電子表格。當我點擊調試時它們不會被創建。
編輯
如果有幫助,截圖:http://i.imgur.com/wyPZ5jz.png
也許「entry.Title.ToString()」包含一些字符不是有效的文件名嗎? –
是否沒有使用某個API調用來代替串聯字符串?這讓我感到很疲倦。 – tuespetre