MS Graph API retrieve one drive worksheet with styling information

Ira Korabelnikov 0 Reputation points
2025-01-27T14:56:20.1633333+00:00

I need to get workbook worksheets with its styling information from onedrive using MS Graph Api java sdk:

final GraphServiceClient graphClient = new GraphServiceClient(credential, SCOPE);

    List<WorkbookWorksheet> worksheets = graphClient
            .drives()
            .byDriveId(drive_id)
            .items()
            .byDriveItemId(item_id)
            .workbook()
            .worksheets()
            .get()
            .getValue();

    if (worksheets == null || worksheets.isEmpty()) {
        log.warn("no worksheets found for item: {}", item_id);
        return null;
    }
    
    for (WorkbookWorksheet worksheet : worksheets) {

        WorkbookRangeFormat rangeWithFormat = graphClient
                .drives()
                .byDriveId(drive_id)
                .items()
                .byDriveItemId(item_id)
                .workbook()
                .worksheets()
                .byWorkbookWorksheetId(worksheet.getId())
                .usedRange()
                .format()
                .get();
        
    }

The problem is that rangeWithFormat doesn't have formatting info.
Is there a way to get the styles (fonts and fill)?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,978 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,295 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saranya Madhu-MSFT 1,340 Reputation points Microsoft Vendor
    2025-01-28T05:10:40.31+00:00

    Hi Ira Korabelnikov,

    Thanks for reaching out to Microsoft!

    As per document, Get RangeFormat - Retrieve the properties and relationships of rangeformat object.A format object encapsulating the range's font, fill, borders, alignment, and other properties.

    Using Graph API, to get range fill

    GET https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets/{id|name}/range(address='<address>')/format/fill
    

    To get range font,

    GET https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets/{id|name}/range(address='<address>')/format/font
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.