gpt4 book ai didi

java - JExcel API : how to change the color of a Cell?

转载 作者:行者123 更新时间:2023-11-30 03:47:26 25 4
gpt4 key购买 nike

我搜索如何更改在 Excel 文件中选择的单元格的颜色。我测试了这段代码:

    WritableCell c = sheet.getWritableCell(0,0);
WritableCellFormat newFormat = new WritableCellFormat(c.getCellFormat());
newFormat.setBackground(Colour.RED);
c.setCellFormat(newFormat);

但是这个例子没有运行。解决办法是什么?

最佳答案

看看这个你可能没有使用 write();并关闭();方法

Workbook wk= Workbook.getWorkbook(new File("ex.xls"));

WritableWorkbook workbook = Workbook.createWorkbook(new File("modifed.xls"), wk);

WritableSheet sheet = workbook.getSheet(0);

WritableCell c = sheet.getWritableCell(0,0);

WritableCellFormat newFormat = new WritableCellFormat();

newFormat.setBackground(Colour.RED);

c.setCellFormat(newFormat);



workbook.write(); // important to use
workbook.close();

关于java - JExcel API : how to change the color of a Cell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25283356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com