Ejemplo n.º 1
0
        /// <summary>
        /// 更新工作表名稱
        /// </summary>
        public static void UpdateSheetTitle(this SheetsService service, string spreadsheetId, string oldName, string newName)
        {
            var sheet = service.GetSheet(spreadsheetId, oldName);

            if (sheet == null)
            {
                throw new NullReferenceException($"Can't find the spreadsheetId {spreadsheetId}, sheetName {oldName}");
            }

            var sheetProperties = new SheetProperties
            {
                SheetId = sheet.Properties.SheetId,
                Title   = newName
            };

            var updateSheetPropertiesRequest = new UpdateSheetPropertiesRequest
            {
                Properties = sheetProperties,
                Fields     = "title"
            };

            //Create a new request with containing the addSheetRequest and add it to the requestList
            var request = new Request
            {
                UpdateSheetProperties = updateSheetPropertiesRequest
            };

            service.BatchUpdateSpreadsheet(spreadsheetId, request);
        }
Ejemplo n.º 2
0
        private IList <BatchUpdateSpreadsheetResponse> BatchUpdateSpreadsheet(InsertRangeEmptyDto[] ranges)
        {
            if (ranges is null)
            {
                throw new System.ArgumentNullException(nameof(ranges));
            }

            return(ranges.Select(c =>
            {
                return CheckSheetExist(c.Sheetname, () =>
                {
                    var request = CreateInsertDimensionRequest(c);
                    return SheetsService.BatchUpdateSpreadsheet(GoogleSheetsApi.SpreadSheetId, request);
                });
            }).ToList());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增工作表
        /// </summary>
        public static void AddSheet(this SheetsService service, string spreadsheetId, string sheetName)
        {
            // 設定工作表名稱到工作表屬性中
            var sheetProperties = new SheetProperties
            {
                Title = sheetName
            };

            // 新增工作表的請求
            var addSheetRequest = new AddSheetRequest
            {
                Properties = sheetProperties
            };

            // 創建一個新的請求
            var request = new Request
            {
                AddSheet = addSheetRequest
            };

            // 送出請求
            service.BatchUpdateSpreadsheet(spreadsheetId, request);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 刪除工作表
        /// </summary>
        public static void DeleteSheet(this SheetsService service, string spreadsheetId, string sheetName)
        {
            var sheet = service.GetSheet(spreadsheetId, sheetName);

            if (sheet == null)
            {
                throw new NullReferenceException($"Can't find the spreadsheetId {spreadsheetId}, sheetName {sheetName}");
            }

            // 創建刪除Sheet指令
            var deleteSheetRequest = new DeleteSheetRequest
            {
                SheetId = sheet.Properties.SheetId
            };

            // 創建一個要求
            var request = new Request
            {
                DeleteSheet = deleteSheetRequest
            };

            // 送出請求
            service.BatchUpdateSpreadsheet(spreadsheetId, request);
        }