Apache POI CellStyle 未得到应用 [英] Apache POI CellStyle is not getting applied

查看:37
本文介绍了Apache POI CellStyle 未得到应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试写入数据时,我还编写了使用 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(sty‌​leGreen); 

推荐答案

重复使用我写的代码:

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 未得到应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆