如何在C#中的Google Sheets API v4中添加工作表? [英] How to add a sheet in google sheets API v4 in C#?
问题描述
我一直在使用Google Sheets API,并遵循 Google指南.但是,即使在Google的第二页之外,也没有任何示例可以添加工作表并写入.NET中的新工作表. js有很多功能,但是我不知道如何1)添加工作表或2)写入新工作表.
I've been using Google Sheets API, and following The Google Guide. However there is no example, even beyond the second page of google, to add a worksheet and write to a new sheet in .NET. There is plenty for js, but I have no idea on how to 1) add a sheet or 2) write to a new sheet.
我该怎么做?现在,我可以像示例一样阅读,没有任何问题,而且我只找到
How can I do this? Right now I'm able to read like in the example with out any problems, and I've only found one other reference to v4 C#. I tried going back to v3, but all documents strongly suggest using v4.
有人能做到这一点吗?到目前为止,这是我所能做的:
Has anyone been able to do this? Here's all I've been able to do so far:
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
// Add new Sheet
string sheetName = string.Format("{0} {1}", DateTime.Now.Month, DateTime.Now.Day);
AddSheetRequest addSheetRequest = new AddSheetRequest();
addSheetRequest.Properties.Title = sheetName;
// How do I tell this to update??
推荐答案
要在以后为某人节省头痛,以消除所有头痛.经过数小时的反复试验,我弄清楚了如何添加工作表. 仍然研究如何更新值.
To save someone in the future a headache to end all headaches. I figured out how to add a sheet after hours of trial and error. Still working on how to update values.
这是我的做法:
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Add new Sheet
string sheetName = string.Format("{0} {1}", DateTime.Now.Month, DateTime.Now.Day);
var addSheetRequest = new AddSheetRequest();
addSheetRequest.Properties = new SheetProperties();
addSheetRequest.Properties.Title = sheetName;
BatchUpdateSpreadsheetRequest batchUpdateSpreadsheetRequest = new BatchUpdateSpreadsheetRequest();
batchUpdateSpreadsheetRequest.Requests = new List<Request>();
batchUpdateSpreadsheetRequest.Requests.Add(new Request
{
AddSheet = addSheetRequest
});
var batchUpdateRequest =
service.Spreadsheets.BatchUpdate(batchUpdateSpreadsheetRequest, spreadsheetId);
batchUpdateRequest.Execute();
这篇关于如何在C#中的Google Sheets API v4中添加工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!