private static GoogleSheetAppendRequest CreateAppendRequest(string sheetName, int columnKey, string valueKey, int columnStart, object[] values) { var row = new GoogleSheetRow(); var countColumns = Math.Max(columnKey, columnStart + values.Length); for (int i = 0; i < countColumns; i++) { row.Add(null); } for (int i = 0; i < values.Length; i++) { row[i + columnStart] = GoogleSheetCell.Create(values[i]); } row[columnKey] = GoogleSheetCell.Create(valueKey); var request = new GoogleSheetAppendRequest(sheetName) { Rows = { row }, }; return(request); }
private static IEnumerable <GoogleSheetUpdateRequest> CreateUpdateRequests(string sheetName, int columnStart, int rowStart, object[] values) { for (int i = 0; i < values.Length; i++) { var value = values[i]; if (value == null) { continue; } var row = new GoogleSheetRow(); row.Add(GoogleSheetCell.Create(value)); var request = new GoogleSheetUpdateRequest(sheetName) { ColumnStart = columnStart + i, RowStart = rowStart, Rows = { row }, }; yield return(request); } }
private CellData CreateCellData(GoogleSheetCell cell) { if (cell == null) { return(new CellData()); } var numberValue = cell.NumberValue; var numberFormat = cell.NumberFormat == null ? null : new NumberFormat { Type = "number", Pattern = cell.NumberFormat, }; if (cell.DateTimeValue.HasValue) { numberValue = cell.DateTimeValue.Value.ToOADate(); numberFormat = new NumberFormat { Type = "number", Pattern = cell.DateTimeFormat ?? DateTimeFormat }; } var userEnteredValue = new ExtendedValue { StringValue = cell.StringValue, NumberValue = numberValue, BoolValue = cell.BoolValue, }; CellFormat userEnteredFormat = null; if (numberFormat != null) { if (userEnteredFormat == null) { userEnteredFormat = new CellFormat(); } userEnteredFormat.NumberFormat = numberFormat; } if (cell.Bold.HasValue) { if (userEnteredFormat == null) { userEnteredFormat = new CellFormat(); } if (userEnteredFormat.TextFormat == null) { userEnteredFormat.TextFormat = new TextFormat(); } userEnteredFormat.TextFormat.Bold = cell.Bold; } if (cell.BackgroundColor.HasValue) { if (userEnteredFormat == null) { userEnteredFormat = new CellFormat(); } userEnteredFormat.BackgroundColor = cell.BackgroundColor.Value.ToGoogleColor(); } if (cell.HorizontalAlignment.HasValue) { if (userEnteredFormat == null) { userEnteredFormat = new CellFormat(); } userEnteredFormat.HorizontalAlignment = cell.HorizontalAlignment.ToString(); } var cellData = new CellData() { UserEnteredValue = userEnteredValue, UserEnteredFormat = userEnteredFormat, }; return(cellData); }