public HSSF(String filename,
boolean write) throws IOException {
short rownum = 0;
FileOutputStream out = new FileOutputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
f.setFontHeightInPoints(( short ) 12);
f.setColor(( short ) 0xA);
f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
f2.setFontHeightInPoints(( short ) 10);
f2.setColor(( short ) 0xf);
f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cs.setFont(f);
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs2.setFillPattern(( short ) 1); // fill w fg
cs2.setFillForegroundColor(( short ) 0xA);
cs2.setFont(f2);
wb.setSheetName(0, "HSSF Test");
for (rownum = ( short ) 0; rownum < 300; rownum++)
{
r = s.createRow(rownum);
if ((rownum % 2) == 0)
{
r.setHeight(( short ) 0x249);
}
// r.setRowNum(( short ) rownum);
for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
{
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_NUMERIC);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
+ (( double ) cellnum / 10000)));
if ((rownum % 2) == 0)
{
c.setCellStyle(cs);
}
c = r.createCell(( short ) (cellnum + 1),
HSSFCell.CELL_TYPE_STRING);
c.setCellValue("TEST");
s.setColumnWidth(( short ) (cellnum + 1),
( short ) ((50 * 8) / (( double ) 1 / 20)));
if ((rownum % 2) == 0)
{
c.setCellStyle(cs2);
}
} // 50 characters divided by 1/20th of a point
}
// draw a thick black border on the row at the bottom using BLANKS
rownum++;
rownum++;
r = s.createRow(rownum);
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
for (short cellnum = ( short ) 0; cellnum < 50; cellnum++)
{
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);
// c.setCellValue(0);
c.setCellStyle(cs3);
}
s.addMergedRegion(new Region(( short ) 0, ( short ) 0, ( short ) 3,
( short ) 3));
s.addMergedRegion(new Region(( short ) 100, ( short ) 100,
( short ) 110, ( short ) 110));
// end draw thick black border
// create a sheet, set its title then delete it
s = wb.createSheet();
wb.setSheetName(1, "DeletedSheet");
wb.removeSheetAt(1);
// end deleted sheet
wb.write(out);
out.close();
}
Constructor HSSF - given a filename this outputs a sample sheet with just
a set of rows/cells. Parameters:
filename -
write -
Throws:
IOException -
- exception:
IOException -
|