/** * Constructor HSSF - given a filename this outputs a sample sheet with just a Set of rows/cells. * * @param filename * @param Write * @exception IOException */ public HSSF(String filename, bool Write) { 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 Chars 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(); }