Saving HSSFCellStyle in Excel file

G

Ghislain Benrais

Hi world,
I'm writing excel files with HSSF libraries and it works very well.
Nevertheless, I think I have misunderstood something about HSSF styles. I'm
afraid they're only available when java is running. Or is it possible to
save them in the excel result, with a nice name, so that the excel user can
modify the applied style ? If could there be a workaround ?
Here is a sample program :

HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet =
wb.createSheet("new sheet"); HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0); cell.setCellValue(1);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(cellStyle.BORDER_THICK); cell =
row.createCell((short)0); cell.setCellValue(1);
cell.setCellStyle(cellStyle); FileOutputStream fileOut = new
FileOutputStream("workbook.xls"); wb.write(fileOut);
fileOut.close();workbook.xls contains a cell with the expected formatting
properties, but its style is 'normal'.Thanks,Ghislain
 
M

Massimo Dell'Andrea

Ghislain said:
Hi world,
I'm writing excel files with HSSF libraries and it works very well.
Nevertheless, I think I have misunderstood something about HSSF styles. I'm
afraid they're only available when java is running. Or is it possible to
save them in the excel result, with a nice name, so that the excel user can
modify the applied style ? If could there be a workaround ?
Here is a sample program :

HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet =
wb.createSheet("new sheet"); HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0); cell.setCellValue(1);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(cellStyle.BORDER_THICK); cell =
row.createCell((short)0); cell.setCellValue(1);
cell.setCellStyle(cellStyle); FileOutputStream fileOut = new
FileOutputStream("workbook.xls"); wb.write(fileOut);
fileOut.close();workbook.xls contains a cell with the expected formatting
properties, but its style is 'normal'.Thanks,Ghislain

Try using HSSFCellStyle.BORDER_THIN
 
G

Ghislain Benrais

Thanks Massimo but the program works ! I get the border I expected. The
trouble is that the cell doesn't have its own style. So suppose I have
thousands of cells with this style, how could the excel user change its
formatting properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top