1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
package jeter;
import java.io.*;
import org.apache.poi.hpsf.CustomProperties;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class CreerFichierWord3 {
public static void main (String[] args) throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("empty.doc"));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
Paragraph par1 = range.insertAfter(new ParagraphProperties(), 0);
par1.setSpacingAfter(200);
par1.setJustification((byte) 1);
CharacterRun run1 = par1.insertAfter("one");
run1.setFontSize(2 * 18);
// font size: twice the point size
Paragraph par2 = run1.insertAfter(new ParagraphProperties(), 0);
par2.setSpacingAfter(200);
CharacterRun run2 = par2.insertAfter("two two two two two two two two two two two two two");
run2.setBold(true);
Paragraph par3 = run2.insertAfter(new ParagraphProperties(), 0);
par3.setFirstLineIndent(200);
par3.setSpacingAfter(200);
CharacterRun run3 = par3.insertAfter("three three three three three three three three three "
+ "three three three three three three three three three three three three three three "
+ "three three three three three three three three three three three three three three");
run3.setItalic(true);
// add a custom document property (needs POI 3.5; POI 3.2 doesn't save custom properties)
DocumentSummaryInformation dsi = doc.getDocumentSummaryInformation();
CustomProperties cp = dsi.getCustomProperties();
if (cp == null)
cp = new CustomProperties();
cp.put("myProperty", "foo bar baz");
dsi.setCustomProperties(cp);
OutputStream out = new FileOutputStream(new File("Exemple.doc"));
doc.write(out);
out.flush();
out.close();
}
} |