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/27 19:02:27 UTC
Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
Hi,
I use POI 2.5.1 so far and plan to migrate to 3.1 now and actually do
the first tests -- and they fail.
Purpose of POI for me: Generate XLS files (simple tables, 1 sheet per
WB) from scratch for download by Windows users
Scenario: My code queries a DB and prepares lists from the results as
Excel files for download by users. No formulas, no special data, no
embedded objects. Formatting only requires things like boldface and
borders and repeatable rows / freeze panes.
Problem with 3.1 final (20080629): When I start to generate and fill a
new workbook from scratch, I receive:
java.lang.IllegalStateException: Cannot create value records before row
records exist
Code dealing with POI HSSF looks like:
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(name);
// name.equals("Vorschauliste")
HSSFRow row = sheet.createRow((short)xlsZeile);
// xlsZeile == 0
HSSFCell cell = row.createCell((short)0);
Stack trace of POI code is:
[27.08.08 13:25:06:825 CEST] 00000020 SystemErr R
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)
// last row: my code.
I looked around and found that there were the following changes in the
code base which may belong to this problem:
Bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=45145
SVN: r663765
I inspected the source code around the stack trace and found that in
Sheet.checkCells() a condition (dealing with the binary sequence of data
records building the Excel file) is checked, but nothing is done before
in "my sequence of calls" to meet this condition. Moreover, I cannot
force or tackle things like dimsloc in my code since they are part of
the private HSSF data model.
What can I do to get my code work with 3.1? (I do not plan to use
template files.)
tia,
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
Posted by Christian Gosch <ch...@inovex.de>.
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
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
Posted by Christian Gosch <ch...@inovex.de>.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45717
--
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
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0)
throws IllegalStateException
Posted by Nick Burch <ni...@torchbox.com>.
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
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
Posted by Christian Gosch <ch...@inovex.de>.
Hi,
attached you find a JUnit test class (source) for the problem.
Package of the test class:
- (default)
Required:
- JUnit (as present in Eclipse 3.4 EE Ganymede),
- POI 3.1 FINAL 20080629
Testing environment was Eclipse 3.4 Ganymede EE and IBM WebSphere
Application Server 6.0.2.19 (with IBM JRE 1.4.2 on WinXP-Pro SP3, which
was set up as the project's JRE).
2 things added:
(1) OK, there is some more code than I provided at first glance, but it
is only formatting stuff, as you will see by inspecting the test case.
(2) I have a "variant" of the code I provide here -- and this variant
works without any problems. If you feel you need this for comparisons, I
can build a second test case based on this "code variant". Of course
there must be a difference, and that difference must be important.
Thanks for investigation,
--
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: Thursday, August 28, 2008 1:28 PM
> To: POI Users List
> Subject: Re: Problem with POI-3.1-final-20080629, HSSF:
> HSSFRow.createCell((short)0) throws IllegalStateException
>
> On Wed, 27 Aug 2008, Christian Gosch wrote:
> > Problem with 3.1 final (20080629): When I start to generate and fill
a
> > new workbook from scratch, I receive:
> >
> > java.lang.IllegalStateException: Cannot create value records before
row
> > records exist
>
> You shouldn't get that on an empty workbook. Any chance you could
write a
> small unit test that triggers the problem, then upload it to bugzilla?
I
> can execute your code snippet just fine, so I can't figure out what's
> wrong for you
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
> !DSPAM:48b68bb822931511210146!
>
>
Re: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0)
throws IllegalStateException
Posted by Nick Burch <ni...@torchbox.com>.
On Wed, 27 Aug 2008, Christian Gosch wrote:
> Problem with 3.1 final (20080629): When I start to generate and fill a
> new workbook from scratch, I receive:
>
> java.lang.IllegalStateException: Cannot create value records before row
> records exist
You shouldn't get that on an empty workbook. Any chance you could write a
small unit test that triggers the problem, then upload it to bugzilla? I
can execute your code snippet just fine, so I can't figure out what's
wrong for you
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Problem with POI-3.1-final-20080629, HSSF: HSSFRow.createCell((short)0) throws IllegalStateException
Posted by Christian Gosch <ch...@inovex.de>.
Little correction: Currently I use "3.0.1 final" successfully, not
2.5.1.
Should have read the manifest before mailing :-(
--cg
> -----Original Message-----
> From: Christian Gosch
> Sent: Wednesday, August 27, 2008 7:02 PM
> To: user
> Subject: Problem with POI-3.1-final-20080629, HSSF:
> HSSFRow.createCell((short)0) throws IllegalStateException
>
> Hi,
>
> I use POI 2.5.1 so far and plan to migrate to 3.1 now and actually do
> the first tests -- and they fail.
>
> Purpose of POI for me: Generate XLS files (simple tables, 1 sheet per
> WB) from scratch for download by Windows users
>
> Scenario: My code queries a DB and prepares lists from the results as
> Excel files for download by users. No formulas, no special data, no
> embedded objects. Formatting only requires things like boldface and
> borders and repeatable rows / freeze panes.
>
> Problem with 3.1 final (20080629): When I start to generate and fill a
> new workbook from scratch, I receive:
>
> java.lang.IllegalStateException: Cannot create value records before
row
> records exist
>
>
> Code dealing with POI HSSF looks like:
>
> HSSFWorkbook workbook = new HSSFWorkbook();
> HSSFSheet sheet = workbook.createSheet(name);
> // name.equals("Vorschauliste")
> HSSFRow row = sheet.createRow((short)xlsZeile);
> // xlsZeile == 0
> HSSFCell cell = row.createCell((short)0);
>
>
> Stack trace of POI code is:
>
> [27.08.08 13:25:06:825 CEST] 00000020 SystemErr R
> 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)
> // last row: my code.
>
>
> I looked around and found that there were the following changes in the
> code base which may belong to this problem:
>
> Bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=45145
> SVN: r663765
>
>
> I inspected the source code around the stack trace and found that in
> Sheet.checkCells() a condition (dealing with the binary sequence of
data
> records building the Excel file) is checked, but nothing is done
before
> in "my sequence of calls" to meet this condition. Moreover, I cannot
> force or tackle things like dimsloc in my code since they are part of
> the private HSSF data model.
>
> What can I do to get my code work with 3.1? (I do not plan to use
> template files.)
>
> tia,
> --
> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
> !DSPAM:48b58acf22931046596568!
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org