私の目的は、.docx ファイルを読み取り、そのテキストをビュー (Web ページ) に表示することです。
Grails アプリケーションで .docx ファイルを読み取るために apache POI を使用しています。空白や改行を失わずにビューに出力を表示する方法を教えてください。
私の .docx ドキュメント コンテンツ
This is a .docx document ...
this is second line
this is third line
私が印刷しているときに読んだ後のGroovyコンソールの結果:
This is a .docx document ...
this is second line
this is third line
しかし、出力をビューに渡すと、
This is a .docx document ... this is second line this is third line
.
My code is :
import org.apache.poi.xwpf.usermodel.XWPFDocument
import org.apache.poi.xwpf.extractor.XWPFWordExtractor
...
String str = "E:\\Query.docx"
File docFile = null;
docFile = new File(str);
FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());
XWPFDocument doc = new XWPFDocument(fis)
XWPFWordExtractor docExtractor = new XWPFWordExtractor(doc)
println docExtractor.getText()
...
ドキュメントの各行を反復する方法を提案できれば、簡単に結果を得ることができます。行き詰まってしまった私を助けてください。