https://poi.apache.org/apidocs/index.ht ... mmary.html
I want to pass a byte array to a POI function but am running into an issue with Javascript types.
This is the code:
Code: Select all
var a=[];
a[0]=new java.lang.String("82").getBytes();
a[1]=new java.lang.String("162").getBytes();
a[2]=new java.lang.String("240").getBytes();
custColor = new XSSFColor(a);
return custColor.getIndex();
When I run this, I get the error
Code: Select all
Cannot convert org.mozilla.javascript.NativeArray@4aafdaff to org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor (GLOBAL_FUNCTIONS#43)
Update: I have been looking into this and found a solution that works.
I've been searching the web some more on how to implement custom colors in POI for XSSF and found this example which works in a normal Java dev environment to create a custom color based on an RGB valueI:
Code: Select all
XSSFColor a = new XSSFColor(new java.awt.Color(128, 0, 128)))
Code: Select all
var a = new XSSFColor(new java.awt.Color(128, 0, 128)))
Code: Select all
Wrapped java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Blue (
Eventually, I was able to fix it by doing this:
Code: Select all
var colorArr=color.split(","); // Color is provided as a csv string like "82,162,240"
return new XSSFColor(new java.awt.Color(parseFloat(colorArr[0]/255),parseFloat(colorArr[1]/255),parseFloat(colorArr[2]/255)))