Bonjour,

Je souhaiterai générer un fichier word grâce à l'api POI.
J'ai une erreur que je ne comprends pas:
ici je créé le fichier mais c'est pour faire des tests, plus tard, je mettrai ce document dans l'"outputStream" de ma "HttpServletResponse" afin de pouvoir télécharger le fichier en cliquant sur un lien.

Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
        byte[] buf = new byte[1024];
        InputStream is = new ByteArrayInputStream(buf);
        HWPFDocument doc = new HWPFDocument(is);
 
        // centered paragraph with large font size
        Range 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);
 
        // 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();
        }
        dsi.setCustomProperties(cp);
 
        OutputStream out = new FileOutputStream(new File("D:/essai.doc"));
        doc.write(out);
 
        out.flush();
        out.close();
Et voici l'erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
run:
Exception in thread "main" java.io.IOException: Invalid header signature; read 0x0000000000000000, expected 0xE11AB1A1E011CFD0
	at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:125)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:153)
	at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:96)
	at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:119)
	at daoTest.poi.main(poi.java:34)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Merci ce votre aide.