I am reading an xlsx file using XSSF of Apache POI. When reading the font of a particular cell and applying in new cell that font is applied for the whole sheet not for that perticular cell. i want for Example:
column1 column2 column3
row1 ARIAL TIMES ROMAN ARIAL
row2 TIMES ROMAN ARIAL ARIAL
row3 ARIAL ARIAL ARIAL
I want the same font in each cell that was in original file.
My code is:
public XSSFCellStyle setFontOnCell(XSSFCellStyle cellStyle, XSSFCell cell)
{
try {
font = cell.getCellStyle().getFont();
new_font.setFontName(font.getFontName());
new_font.setBoldweight(font.getBoldweight());
new_font.setFontHeight((short)font.getFontHeight());
new_font.setFamily(font.getFamily());
cellStyle.setFont(new_font);
return cellStyle;
} catch (Exception e) {
//System.out.println(e.getMessage());
return cellStyle;
}
}
Your
new_fontseems to be a global variable, and you keep changing it and then injecting it into cells. It should be local tosetFontOneCell()so that each cell gets its ownFontinstance, instead of all of them actually using the same object,