I tried page break feature of POI-2.5-FINAL, and got trouble. I create a new workbook file with Excel and call HSSFSheet#getRowBreaks(), then it raises NullPointerException. (1) create a new workbook file (three sheets and no data) with Excel. I tried with Excel 2000 and XP. (2) create HSSFWorkbook instance for (1)'s workbook. (3) call workbook.getSheetAt() to get sheet. (4) call sheet.getRowBreaks(). It raises NPE. Environments: Windows2000 J2SE 1.4.2_03 MS Excel2000 POI-2.5-FINAL Here is the stack trace. --- java.lang.NullPointerException at org.apache.poi.hssf.model.Sheet.getNumRowBreaks(Sheet.java:2764) at org.apache.poi.hssf.usermodel.HSSFSheet.getRowBreaks(HSSFSheet.java: 1144) at POISample.handleSheet(POISample.java:41) at POISample.main(POISample.java:26) Exception in thread "main" --- and sample code --- public class POISample { public static void main(final String[] args) throws Exception { final HSSFWorkbook book = new HSSFWorkbook(new FileInputStream(args[0])); POISample.handleSheet(book.getSheetAt(0)); book.write(new FileOutputStream(args[1])); } private static void handleSheet(final HSSFSheet sheet) { for (int i = 0; i < 5; ++i) { final HSSFRow row = sheet.createRow(i); for (short j = 0; j < 5; ++j) { final HSSFCell cell = row.createCell(j); cell.setCellValue(i + ":" + j); } } final int[] breaks = sheet.getRowBreaks(); sheet.setRowBreak(1); } } --- Additionally, in some cases i succeeded calling getRowBreaks(). If the sheet already has some page breaks, or the sheet is created with HSSFWorkbook#createSheet(), it succeeds. kind regards. IRIE Hironori
I'm getting a very similar problem with POI2.5-final when using HSSFSheet.setRowBreak(int). NPE if the workbook has not already RowBreaks. My workaround: As I use a template originally without RowBreaks I introduce a temporary RowBreaks into the template which I then delete from the application (using getRowBreaks()) and after this I put the real RowBreaks at the lines they should go. Jan-Martin Roth (jmroth@mtg.de)
fixed in SVN Jason
I'm so sorry for my late verification. I checked with POI 3.0.1 and worked collect.