Ich generiere eine .docx-Datei in einer JAX-RS-API.try (FileOutputStream fos = new FileOutputStream("localSavedFile.docx")) {
outputDocument(fos);
< /code>
} < /p>
Die Datei wird in MS -Wort gut geöffnet.StreamingOutput stream = output -> {
try {
outputDocument(output);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
return Response.ok(stream)
.header("Content-Disposition", "attachment; filename=\"file.docx\"")
.type("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
.build();
< /code>
Wort zeigt einen Kompatibilitätsfehler (so etwas wie „Die Datei ist beschädigt oder kann nicht richtig geöffnet werden“) beim Öffnen der heruntergeladenen Datei.public void outputDocument(final OutputStream outputStream) throws Exception {
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
//other code where docx is generated
// finally write the package to the provided stream
wordPackage.save(outputStream);
< /code>
} < /p>
Was ich ausprobiert habe: < /p>
Speichern mit FileOutputStream funktioniert einwandfrei (das Dokument selbst ist gültig). In eine lokale Datei geschrieben, zeigt jedoch einen Kompatibilitätsfehler an, wenn er in einer JAX-RS-Antwort gestreamt wird?>
Die von der JAX-RS API generierte DOCX-Datei zeigt Kompatibilitätsfehler im Wort an ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post