问题描述
当我尝试写入数据时,我还编写了使用Cell Style类设置Cell Style的代码.代码执行后.它创建只包含数据而不是单元格样式的excel文件.谁能告诉我为什么?我也在各处搜索.我的代码与所有建议的代码相同.
When I tried to write data, i also wrote code to set Cell Style using Cell Style class. after execution of the code. it creates excel file with just data not cell Styles. Can anyone please tell me why? I also search everywhere. My Code is same as what every where suggested.
CellStyle styleGreen = cell.getRow().getSheet().getWorkbook().createCellStyle();
styleGreen.setBorderBottom(CellStyle.BORDER_MEDIUM_DASHED);
cell.setCellStyle(styleGreen);
推荐答案
重新使用您编写的代码:
Re-using your code I simply wrote :
CellStyle styleGreen = cell.getRow().getSheet().getWorkbook().createCellStyle();
styleGreen.setBorderBottom(CellStyle.BORDER_MEDIUM_DASHED);
cell.setCellValue("value"); // testing with some value in the cell
cell.setCellStyle(styleGreen);
它奏效了,这就是为什么我认为错误是由您的以下代码引起的,请确保您不要在下面的代码中重复使用此样式,否则最终将修改前面的单元格,而只需创建一个新的.
And it worked , that's why I suppose the error come from your following code , make sure you do not re-use this style in your code below otherwise you'll end up modifying the previous cells, instead just create a new one.
这篇关于Apache POI CellStyle未得到应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!