This article describes how to use Excel workbooks and charts APIs in Microsoft Graph to update the properties of the rangeFormat, rangeFill, and rangeFont properties of a specified range.
The result of this set of requests is a table with three cells formatted like the top three cells in the following image.
Example 1: Cell 1 alignment and height
The following request updates the vertical alignment, row height, and column height of the first cell.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new WorkbookRangeFormat
{
ColumnWidth = 135d,
VerticalAlignment = "Top",
RowHeight = 49d,
WrapText = false,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Worksheets["{workbookWorksheet-id}"].Range().Format.PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewWorkbookRangeFormat()
columnWidth := float64(135)
requestBody.SetColumnWidth(&columnWidth)
verticalAlignment := "Top"
requestBody.SetVerticalAlignment(&verticalAlignment)
rowHeight := float64(49)
requestBody.SetRowHeight(&rowHeight)
wrapText := false
requestBody.SetWrapText(&wrapText)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
format, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Workbook().Worksheets().ByWorkbookWorksheetId("workbookWorksheet-id").RangeWithAddress(&address).Format().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new WorkbookRangeFormat
{
ColumnWidth = 135d,
HorizontalAlignment = "Center",
VerticalAlignment = "Center",
RowHeight = 49d,
WrapText = false,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Worksheets["{workbookWorksheet-id}"].Range().Format.PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewWorkbookRangeFormat()
columnWidth := float64(135)
requestBody.SetColumnWidth(&columnWidth)
horizontalAlignment := "Center"
requestBody.SetHorizontalAlignment(&horizontalAlignment)
verticalAlignment := "Center"
requestBody.SetVerticalAlignment(&verticalAlignment)
rowHeight := float64(49)
requestBody.SetRowHeight(&rowHeight)
wrapText := false
requestBody.SetWrapText(&wrapText)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
format, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Workbook().Worksheets().ByWorkbookWorksheetId("workbookWorksheet-id").RangeWithAddress(&address).Format().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new WorkbookRangeFormat
{
ColumnWidth = 135d,
HorizontalAlignment = "Right",
VerticalAlignment = "Top",
RowHeight = 49d,
WrapText = false,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Worksheets["{workbookWorksheet-id}"].Range().Format.PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewWorkbookRangeFormat()
columnWidth := float64(135)
requestBody.SetColumnWidth(&columnWidth)
horizontalAlignment := "Right"
requestBody.SetHorizontalAlignment(&horizontalAlignment)
verticalAlignment := "Top"
requestBody.SetVerticalAlignment(&verticalAlignment)
rowHeight := float64(49)
requestBody.SetRowHeight(&rowHeight)
wrapText := false
requestBody.SetWrapText(&wrapText)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
format, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Workbook().Worksheets().ByWorkbookWorksheetId("workbookWorksheet-id").RangeWithAddress(&address).Format().Patch(context.Background(), requestBody, nil)