Web UI に表示するには、.docx ファイルのコンテンツを HTML テキストに変換する必要があります。
Apache POIのXWPFDocumentクラスを使用しましたが、まだ結果を得ることができませんでした。空の文字列を取得しています。私のコードはこのサンプルに基づいています。
これも私のコードです:
public JSONObject uploadDocxFile(MultipartFile multipartFile) throws Exception {
InputStream inputStream = multipartFile.getInputStream();
XWPFDocument wordDocument = new XWPFDocument(inputStream);
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StringWriter stringWriter = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, new StreamResult(stringWriter));
out.close();
String result = new String(out.toByteArray());
String htmlText = result;
JSONObject jsonObject = new JSONObject();
jsonObject.put("content", htmlText);
jsonObject.put("success", true);
return jsonObject;
}