Skip to content
Advertisement

How to make solid color for databar in apache.poi

I’m trying to create a sheet with progress bar which will represent some progress.

I’m using these libraries:

  1. org.apache.poi:poi:4.1.0
  2. org.apache.poi:poi-ooxml:4.1.0
  3. org.apache.poi:poi-ooxml-schemas:4.1.0

All I get is a progress bar with gradient, but I need a progress bar with solid color instead color scale.

Advertisement

Answer

All conditional formatting data bars defined in Office Open XML are using gradient colors. There is not even a attribute or property to change that. Later Excel versions are using extensions from namespace x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main". But those are not part of the Ecma Office Open XML File Formats Standard.

Apache poi until now only bases on Ecma Office Open XML File Formats Standard. So the only way to make solid color for conditional formatting data bar in apache poi is creating the XML of the extended x14 data bar conditional formatting from scratch.

Complete example:

JavaScript

This code will only work properly always for new created XSSFWorkbook. If the XSSFWorkbook was created from an existing workbook, the this could contain org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList for x14 extensions already. If so, then these must be taken into account. But that would be a much more complex and challenging project.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement