开发者

JXL Attempt to modify a referenced format while setting background color

开发者 https://www.devze.com 2023-03-30 07:30 出处:网络
While trying to execute the below code: Colour selectedColour = Colour.WHITE; myWritableCellFormat.setBackground(selectedColour);

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消