1

Im trying to append a cell in a sheet, for example the cell 1A has a border and filled with color grey and I want to insert a string "hello", but using

cell.setCellValue("hello");

destroy the cell format or rather make the cell format in default mode. I know how to use the

CellStyle cs = workbook.createCellStyle();

method but in my project I'm inserting many different data with different cell format. I googled it and no luck finding an answer. Is there another way to solve my problem?

To elaborate my problem. In my sheet in 1A I have a cell format Cell format (fill with color grey and have thin border)

but when I use

 cell.setCellValue("hello");

it makes the cell's format become default but I want my cell to become like this without using CellStyle cs = workbook.createCellStyle(); cell I want

Is there a way to this?

1 Answers1

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

but if you are create a new cell by using

cell = sh.createRow(0).createCell(0); 

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

Raghav2580
  • 256
  • 2
  • 10