You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Christian Gosch <ch...@inovex.de> on 2008/08/31 15:28:38 UTC
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
However, here it is:
// ***********************************************
// Copyright (c) 2002-2008, inovex GmbH, Pforzheim, Germany
import junit.framework.TestCase;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFFooter;
import org.apache.poi.hssf.usermodel.HSSFHeader;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
* @author inovex GmbH (christian)
* @version $Id: $
* Created 29.08.2008
*/
public class TestPOI31Final extends TestCase {
/**
* @param name
*/
public TestPOI31Final(String name) {
super(name);
}
/**
* setUp
* @see junit.framework.TestCase#setUp()
*
* @throws java.lang.Exception
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* tearDown
* @see junit.framework.TestCase#tearDown()
*
* @throws java.lang.Exception
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Test method for {@link
org.apache.poi.hssf.usermodel.HSSFRow#createCell(short)}.
*/
public void testCreateCellShort() {
try {
// Testcase for a problem in POI 3.1-FINAL-20080629
HSSFWorkbook workbook = new HSSFWorkbook();;
// create workbook and sheet
HSSFSheet sheet = workbook.createSheet("Vorschauliste");
HSSFRow row = sheet.createRow((short)0);
// apply sheet settings (basic formatting)
sheet.setMargin(HSSFSheet.LeftMargin, 0.3);
sheet.setMargin(HSSFSheet.RightMargin, 0.3);
sheet.setMargin(HSSFSheet.TopMargin, 0.5);
sheet.setMargin(HSSFSheet.BottomMargin, 0.5);
sheet.setAutobreaks( true); // show automatic page breaks or
not
sheet.setDisplayGridlines(true);
sheet.setDisplayRowColHeadings(true);
sheet.setDisplayGuts(true);
sheet.setGridsPrinted(true);
sheet.setPrintGridlines(true); // identisch??
HSSFPrintSetup ps = sheet.getPrintSetup();
ps.setLandscape( true);
ps.setHeaderMargin( 0.3);
ps.setFooterMargin( 0.3);
ps.setPaperSize( HSSFPrintSetup.A4_PAPERSIZE);
sheet.setFitToPage(true);
ps.setFitWidth((short)1);
ps.setFitHeight((short)0);
HSSFFooter footer = sheet.getFooter();
HSSFHeader header = sheet.getHeader();
header.setLeft("");
header.setCenter("a-Xpedite: Testverteiler / teaminterne
Adressen (Personen im Verteiler: 4)");
header.setRight("(Christian Gosch / Inovex GmbH)");
footer.setLeft("29.08.2008 18:17");
footer.setCenter("Vorschauliste");
footer.setRight("Seite &P von &N");
workbook.setRepeatingRowsAndColumns( 0, 0, 0, 0, 0 + 0);
sheet.createFreezePane( 1, 1 + 0);
// proceed in building sheet
// write header (column names)
// Create a new font and alter it.
HSSFFont fontheadline = workbook.createFont();
fontheadline.setFontHeightInPoints((short)10);
fontheadline.setFontName("Arial");
fontheadline.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// create a style for headlines:
HSSFCellStyle boldFormat = workbook.createCellStyle();
boldFormat.setFont(fontheadline);
HSSFCell cell = row.createCell((short)0);
// terminates with exception:
/*
[29.08.08 18:23:21:702 CEST] ERROR [WebContainer : 6]
XLSViewSrv.specialList(): java.lang.IllegalStateException: Cannot create
value records before row records exist
java.lang.IllegalStateException: Cannot create value records before
row records exist
at org.apache.poi.hssf.model.Sheet.checkCells(Sheet.java:497)
at
org.apache.poi.hssf.model.Sheet.addValueRecord(Sheet.java:1041)
at
org.apache.poi.hssf.usermodel.HSSFRow.createCell(HSSFRow.java:134)
at
org.apache.poi.hssf.usermodel.HSSFRow.createCell(HSSFRow.java:115)
at
de.dc.jnet.frame.servlet.XLSViewSrv.specialList(XLSViewSrv.java:1605)
at
de.dc.jnet.frame.servlet.XLSViewSrv.exportFormulaList(XLSViewSrv.java:12
91)
at
de.dc.jnet.frame.servlet.XLSViewSrv.doDispatch(XLSViewSrv.java:525)
at
de.dc.jnet.frame.servlet.XLSViewSrv.doGet(XLSViewSrv.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
[...]
*/
/* Execution environment: IBM WebSphere 6.0.2.19 (IBM JRE 1.4.2),
POI 3.1-FINAL-20080629 */
System.out.println(cell);
System.out.println("OK -- no error here");
} catch (Throwable t) {
fail("ERROR: " + t);
t.printStackTrace();
System.out.println("ERROR: " + t);
}
}
}
// ***********************************************
Not that sophisticated, but it should do.
--
Dipl.-Inform. Christian Gosch
Systems Development
inovex GmbH
Karlsruher Strasse 71
D-75179 Pforzheim
Tel: 07231 3191-85
Fax: 07231 3191-91
c.gosch@inovex.de
www.inovex.de
Sitz der Gesellschaft: Pforzheim
AG Mannheim, HRB 502126
Geschäftsführer: Stephan Müller
> -----Original Message-----
> From: Nick Burch [mailto:nick@torchbox.com]
> Sent: Friday, August 29, 2008 7:34 PM
> To: POI Users List
> Subject: RE: Problem with POI-3.1-final-20080629, HSSF:
> HSSFRow.createCell((short)0) throws IllegalStateException
>
> On Fri, 29 Aug 2008, Christian Gosch wrote:
> > attached you find a JUnit test class (source) for the problem.
>
> Alas there was no attachment...
>
> If your mail server is proving useless, it might be easier to open a
new
> bug on bugzilla, and attach your unit test there
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
> !DSPAM:48b8331922931207336982!
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org