本文介绍了如何在C#中的Google Sheets API v4中添加工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用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.
推荐答案
要在以后为某人节省头痛,以消除所有头痛.经过数小时的反复试验,我弄清楚了如何添加工作表. 仍然研究如何更新值.
// 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中添加工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!