Google Slides API, able to use Hexadecimal to set Colors?

Viewed 242

Is it possible to set Element Shape background color with Hexadecimal format eg #B6D7A8 ? I see an example here, Google Slides API- How to change text color for all shapes of a certain color

However, the Google Slide API reference does not mention it. I want to be sure, and specifically for Java environment.

https://developers.google.com/slides/reference/rest/v1/presentations.pages/other#Page.OpaqueColor

    requests.add(new Request()
            .setUpdateShapeProperties(new UpdateShapePropertiesRequest()
                .setObjectId(elementRandomString)
                    .setShapeProperties(new ShapeProperties()
                            .setShapeBackgroundFill(new ShapeBackgroundFill()
                                .setSolidFill(new SolidFill()
                                        .setColor(new Col)

enter image description here

1 Answers

The answer provided in the post Google Slides API- How to change text color for all shapes of a certain color uses Slide Service in Apps Script to set the color.

To answer your question, it is not possible to set the color in HEX format. As mentioned in the reference document that you provided, You need to provide an RgbColor object in your OpaqueColor.

Workaround:

  1. Convert your hex color to RGB then divide red, blue and green value by 255 to obtain the RgbColor accepted value which is 0.0 ~ 1.0

You might want to consider this as reference: java : convert Hex color #RRGGBB to rgb r g b?

  1. Set RgbColor based on your converted red, blue and green value.

Sample Code:

requests.add(new Request()
            .setUpdateShapeProperties(new UpdateShapePropertiesRequest()
                .setObjectId(elementRandomString)
                    .setShapeProperties(new ShapeProperties()
                            .setShapeBackgroundFill(new ShapeBackgroundFill()
                                .setSolidFill(new SolidFill()
                                        .setColor(new Color()
                                                .setRgbColor(new RgbColor()
                                                      .setRed(redFloatValue)
                                                      .setBlue(blueFloatValue)
                                                      .setGreen(greenFloatValue))))))));

References:

Related