TEST NAME: Test Write Sheet Style
OBJECTIVE: Test that HSSF can create a simple spreadsheet with numeric and string values and styled with colors
and borders.
SUCCESS: HSSF creates a sheet. Filesize matches a known good. HSSFSheet objects
Last row, first row is tested against the correct values (99,0).
FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good.
HSSFSheet last row or first row is incorrect.
File file = TempFile.createTempFile("testWriteSheetStyle",
".xls");
FileOutputStream out = new FileOutputStream(file);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFFont fnt = wb.createFont();
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setFillForegroundColor(( short ) 0xA);
cs.setFillPattern(( short ) 1);
fnt.setColor(( short ) 0xf);
fnt.setItalic(true);
cs2.setFillForegroundColor(( short ) 0x0);
cs2.setFillPattern(( short ) 1);
cs2.setFont(fnt);
for (short rownum = ( short ) 0; rownum < 100; rownum++)
{
r = s.createRow(rownum);
// r.setRowNum(( short ) rownum);
for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
{
c = r.createCell(cellnum);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
+ (( double ) cellnum / 10000)));
c.setCellStyle(cs);
c = r.createCell(( short ) (cellnum + 1));
c.setCellValue("TEST");
c.setCellStyle(cs2);
}
}
wb.write(out);
out.close();
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb);
assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
// assert((s.getLastRowNum() == 99));