JXL Attempt to modify a referenced format while setting background color
While trying to execute the below code:
Colour selectedColour = Colour.WHITE;
myWritableCellFormat.setBackground(selectedColour);
I am getting this Exception:
jxl.write.biff.JxlWriteException: Attempt to modify a referenced format
Why is this? For reference I've used the same object before these 2 lines to write a cell with another color. Is this of any 开发者_C百科importance?
If you want to change the color for different cell, you need to create the different WritableFont
object and have to pass to WritableCellFormat
constructor.
i.e every time you need to create new objects for WritableFont, WritableCellFormat classes.
WritableFont font = new WritableFont(WritableFont.createFont("Calibri"), 11);
WritableCellFormat format = new WritableCellFormat(font);
format.setBackground(Colour.LIGHT_GREEN, Pattern.SOLID);
精彩评论