Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

java - Apache POI CellStyle is not getting applied

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); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...