Format Excel Spreadsheet Cell Styles in PHP with Aspose.Cells REST API

Folks,

I was able to figure out how to fashion an api request to change a cell’s style by requesting a cell’s style from the api. I’m running into a little bit of an issue however with changing the background color and was wondering if someone can direct me toward an answer. Below is the data structure I’m sending (converted to json) in the request:

[
    'BackgroundColor' => [
        'R'=>248,
        'G'=>248,
        'B'=>255,
        'A'=>255
    ],
    'Font' => [
         'IsBold'=>true
    ]
]

The font weight is changing, but not the background color.

Also, if anyone knows, a way to set the style for a range would be nice, I’m trying to limit the amount of rest calls to the server for expediency.

I’m using the Cells Cloud Laravel SDK and the Worksheet::setCellStyle($cell, $style)

Once again, any help would be greatly appreciated.

Thanks!

Trent

@trent.bean

Thank you for contacting support and sharing details.

Please read Colors and Background Patterns docs to build a better understanding of Cells Formatting.

Cell’s foreground or background color properties will only take effect if the Style object’s Pattern property is configured.

So, in order to set Cell’s background, please send following JSON in request’s body.

[
    'ForegroundColor' => [
        'R'=>248,
        'G'=>248,
        'B'=>255,
        'A'=>255
    ],
    'Pattern'=>'Solid',
    'Font' => [
         'IsBold'=>true
    ]
]

If you require any further information, feel free to contact us.

Thanks for your reply on this, I was able to quickly add this in to get what I wanted.

I see that styles can be set to a range of cells in the .NET SDK, but how do you accomplish the same thing in the Cloud API?

Currently the call used to set the style is:

/cells/{filename}/worksheets/{worksheet name}/cells/{target cell}/style

Can I do something like:

/cells/{filename}/worksheets/{worksheet name}/cells/{range}/style

Thanks!

Trent

@trent.bean

Yes, you can use the following API.
POST /cells/{name}/worksheets/{sheetName}/cells/style
Parameters: name (String, Path), sheetName (String, Path), range (String, Query) and style (Style, Body)
PHP Example: https://github.com/aspose-cells-cloud/aspose-cells-cloud-php/blob/master/test/Api/CellsControllerTest.php
For a complete list of Aspose.Cells Cloud APIs, please check Swagger UI.

Should you need any further information, please do not hesitate to contact us.