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
|
File f = new File(user.getRept()+"/rapport/empty.doc");
File fout = new File(user.getRept()+"/rapport/"+mdl.getCurrent().getPatient().getNom()+"_"+new SimpleDateFormat("ddMMyyyy_hhmmss").format(new Date())+".doc");
fout.createNewFile();
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
HWPFDocument doc = new HWPFDocument(fs);
// centered paragraph with large font size
Range range = doc.getRange();
Paragraph par1 = range.insertAfter(new ParagraphProperties(), 0);
par1.setSpacingAfter(200);
par1.setJustification((byte) 1);
// justification: 0=left, 1=center, 2=right, 3=left and right
CharacterRun run1 = par1.insertAfter("one");
run1.setFontSize(2 * 18);
// font size: twice the point size
// paragraph with bold typeface
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 with italic typeface and a line indent in the first line
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(fout);
doc.write(out);
out.flush();
out.close();
return; |
Partager