POI JAVA 在不影响单元格格式的情况下追加单元格

Fra*_*uez 1 java apache-poi

我试图在工作表中附加一个单元格,例如单元格 1A 有一个边框并用灰色填充,我想插入一个字符串“你好”,但使用

cell.setCellValue("hello");
Run Code Online (Sandbox Code Playgroud)

破坏单元格格式或将单元格格式设为默认模式。我知道如何使用

CellStyle cs = workbook.createCellStyle();
Run Code Online (Sandbox Code Playgroud)

方法,但在我的项目中,我插入了许多具有不同单元格格式的不同数据。我用谷歌搜索它并没有找到答案。还有其他方法可以解决我的问题吗?

详细说明我的问题。在我 1A 的工作表中,我有一个单元格格式 单元格格式(用灰色填充并有细边框)

但是当我使用

 cell.setCellValue("hello");
Run Code Online (Sandbox Code Playgroud)

它使单元格的格式成为默认格式,但我希望我的单元格在不使用我想要的单元格的情况下变成这样CellStyle cs = workbook.createCellStyle();

有没有办法做到这一点?

use*_*136 5

I believe you have an excel workbook and you wanna append data to it. If you wanna keep the existing format and insert data to it you can do that using below code

cell = sheet.getRow(0).getCell(0);
cell.setCellValue("Hellooooo");
Run Code Online (Sandbox Code Playgroud)

but if you are create a new cell by using

cell = sh.createRow(0).createCell(0); 
Run Code Online (Sandbox Code Playgroud)

then you're destroying the current format, in that case you have to create all required cellStyle all over again.