ASF Bugzilla – Attachment 24022 Details for
Bug 47563
Exception when working with table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
creates DOC files with tables in various sizes; only the 2x2 table is OK
CreateWordDocTable.java (text/x-java), 1.89 KB, created by
udittmer
on 2009-07-23 03:53:46 UTC
(
hide
)
Description:
creates DOC files with tables in various sizes; only the 2x2 table is OK
Filename:
MIME Type:
Creator:
udittmer
Created:
2009-07-23 03:53:46 UTC
Size:
1.89 KB
patch
obsolete
> import java.io.*; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.usermodel.*; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class CreateWordDocTable { public static void main (String[] args) throws Exception { test(1, 5); test(1, 6); test(5, 1); test(6, 1); test(2, 2); test(3, 2); test(2, 3); test(3, 3); /* Only works for the 2x2 table; all others throw exceptions like this one: java.lang.IllegalArgumentException: The end (15) must not be before the start (17) at org.apache.poi.hwpf.usermodel.Range.sanityCheckStartEnd(Range.java:247) at org.apache.poi.hwpf.usermodel.Range.<init>(Range.java:181) at org.apache.poi.hwpf.usermodel.Paragraph.<init>(Paragraph.java:103) at org.apache.poi.hwpf.usermodel.Range.getParagraph(Range.java:830) at CreateWordDocTable.test(CreateWordDocTable.java:31) at CreateWordDocTable.main(CreateWordDocTable.java:12) */ } private static void test (int rows, int columns) throws Exception { // POI apparently can't create a document from scratch, // so we need an existing empty dummy document POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("empty.doc")); HWPFDocument doc = new HWPFDocument(fs); Range range = doc.getRange(); Table table = range.insertBefore(new TableProperties(columns), rows); for (int rowIdx=0; rowIdx<table.numRows(); rowIdx++) { TableRow row = table.getRow(rowIdx); System.out.println("row "+rowIdx); for (int colIdx=0; colIdx<row.numCells(); colIdx++) { TableCell cell = row.getCell(colIdx); System.out.println("column "+colIdx+", num paragraphs "+cell.numParagraphs()); try { Paragraph par = cell.getParagraph(0); par.insertBefore(""+(rowIdx*row.numCells()+colIdx)); } catch (Exception ex) { ex.printStackTrace(); } } } doc.write(new FileOutputStream("table-test-"+rows+"-"+columns+".doc")); } }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 47563
: 24022