Hello,
I'm pretty new to java and apache poi. Recently I'm trying to create a
document including several tables. I read your posts and code and tried to
implement a little document on my own. Here's the method I'm using:
public void insertTable(String inputFilename, String outputFilename) {
File inputFile = null;
File outputFile = null;
FileInputStream fis = null;
FileOutputStream fos = null;
HWPFDocument document = null;
Range overallRange = null;
Table table = null;
try {
inputFile = new File(inputFilename);
fis = new FileInputStream(inputFile);
POIFSFileSystem fs = new POIFSFileSystem(fis);
document = new HWPFDocument(fs);
// Get the overall Range
overallRange = document.getRange();
// Set a bold, italic, big heading
CharacterRun run1 = overallRange.insertAfter("table");
run1.setBold(true);
run1.setItalic(true);
run1.setFontSize(36);
//trying to insert a paragraph. Works but neutralizes the
formatting of run1 and par1
/*Paragraph par1 = overallRange.insertAfter(new
ParagraphProperties(), 0);
par1.setSpacingAfter(200);
CharacterRun run2 = par1.insertAfter("paragraph number one");
run2.setBold(true);*/
// trying to insert a table, but word says document is corrupted
/*TableProperties tp = new TableProperties(3);
table = overallRange.insertBefore(tp, 3);
fis.close();
fis = null;
outputFile = new File(outputFilename);
fos = new FileOutputStream(outputFile);
document.write(fos);
}
catch(Exception ex) {
System.out.println("Caught an: " + ex.getClass().getName());
System.out.println("Message: " + ex.getMessage());
System.out.println("Stacktrace follows........");
ex.printStackTrace(System.out);
}
}
Everythig works fine, until I include the first commented code (Paragraph
1), afterwards the document is still readable with word but all formattings
are gone. When I include the commented table code, I get an error by word,
saying the document is damaged.
In the hwpf javadocs I could not find a different way to implement tables.
Can anyone give me a hint what I'm doing wrong, especially with the tables?
Thanks and Greetings
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Create-and-read-table-cotents-in-doc-file-tp4293563p4346155.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]