GoogleSheets

Formatting Ranges

FormatRange sets the range to format using A1 notation. WithFormatType selects the formatting category (HorizontalAlignment, CellBackgroundColor, and so on). WithFormatValue sets a general format value as an object. WithAlignmentFormatValue sets horizontal or vertical alignment using the respective enum. WithColorFormatValue sets the background or text color. WithNumberFormatValue applies a number format (Currency, Percent, Date, etc.). WithTextRotationFormatValue sets the cell text rotation angle.

Examples

GPAL Fluent: High-level fluent C# API

//FormatRange, WithFormatType, and the format value method must all be called in sequence. Each combination of FormatType and format value method corresponds to a distinct Google Sheets formatting API call.

// the Sheets object first, then the credentials that drive the API

GoogleSheets sheets = (GoogleSheets)GPAL.GoogleSheets.ToGPALObject();

sheets.WithCredentials(googleCreds);


// Center-align a header row

sheets

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Report")

.WithFormatType(FormatType.HorizontalAlignment)

.WithAlignmentFormatValue(HorizontalAlignmentType.CENTER)

.FormatRange("A1:F1");


// Apply currency format to a column

sheets

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Sales")

.WithFormatType(FormatType.NumberFormat)

.WithNumberFormatValue(NumberFormatType.CURRENCY);

💬 Ask GPAL