GoogleSheets

Formatting Ranges

FormatRange sets the range to format using A1 notation. WithFormatType selects the formatting category (Alignment, Background, etc.). 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.

// Center-align a header row

GPAL.GoogleSheets

.WithCredentials(googleCreds)

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Report")

.FormatRange("A1:F1")

.WithFormatType(FormatType.Alignment)

.WithAlignmentFormatValue(HorizontalAlignmentType.Center);


// Apply currency format to a column

GPAL.GoogleSheets

.WithCredentials(googleCreds)

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Sales")

.FormatRange("D2:D500")

.WithFormatType(FormatType.NumberFormat)

.WithNumberFormatValue(NumberFormatType.Currency);

💬 Ask GPAL