Java 如何使用ApachePOI获取文件的全部内容?
我尝试在JavaAPI ApachePOI的帮助下读取文件.docx。我使用:Java 如何使用ApachePOI获取文件的全部内容?,java,ms-word,apache-poi,docx,Java,Ms Word,Apache Poi,Docx,我尝试在JavaAPI ApachePOI的帮助下读取文件.docx。我使用: public static String view(String nameDoc){ String text = null; try{ XWPFDocument docx = new XWPFDocument( new FileInputStream(nameDoc)); XWPFWordExtractor we = new XWPFWo
public static String view(String nameDoc){
String text = null;
try{
XWPFDocument docx = new XWPFDocument(
new FileInputStream(nameDoc));
XWPFWordExtractor we = new XWPFWordExtractor(docx);
text = we.getText();
we.close();
docx.close();
}catch (Exception e){
e.printStackTrace();
}
return text;
}
在这种情况下,我只得到一个文本文件,但我的文件包括一个文本、表格、图片。。。如何获取文件的完整内容
String contents = "";
try {
System.out.println("Starting the test");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("D:/Resume.doc"));
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
OutputStream file = new FileOutputStream(new File("D:/test.pdf"));
PdfWriter parser = PdfWriter.getInstance(doc, file);
parser.parse();
PDDocument pdfDocument = parser.getPDDocument();
PDFTextStripper stripper = new PDFTextStripper();
contents = stripper.getText(pdfDocument);
pdfDocument.close();
} catch (Exception e) {
logger.error(e.getMessage());
}
在contents
中,您可以获得文件的完整内容
在
contents
中,您可以获得文件的完整内容。它是docx而不是pdfit,它不提供完整内容(包括图像、表格等),只提供文本content@NicolasFilotto,有关提取图像,请参阅变量文档的位置
PdfWriter parser=PdfWriter.getInstance(文档、文件)
parser.parse()代码>找不到方法parse()
@Oleg1n其doc
它是一个docx而不是一个pdfit不提供全部内容(包括图像、表格..),但只提供文本content@NicolasFilotto,有关提取图像,请参阅变量文档的位置
PdfWriter parser=PdfWriter.getInstance(文档、文件)
parser.parse()
找不到方法parse()
@Oleg1n-itsdoc
查看我的答案,它会起作用并帮助您..您所说的“文件的全部内容”是什么意思?例如,我看不到如何在文本字符串中获取图片……这个答案应该有助于查看我的答案,它将起作用并帮助您……您所说的“文件的全部内容”是什么意思?例如,我看不出如何在文本字符串中获取图片……这个答案应该会有所帮助