如何使用 Java/Apache POI 获取文件摘要信息 [英] How to get file summary information with Java/Apache POI
本文介绍了如何使用 Java/Apache POI 获取文件摘要信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 JAVA 从文件中获取摘要信息,但找不到任何内容.我试过 org.apache.poi.hpsf.*
.
i'am trying to get the summary information from file with JAVA and I can't found anything. I tried with org.apache.poi.hpsf.*
.
我需要作者、主题、评论、关键字和标题.
I need Author, Subject, Comments, Keywords and Title.
File rep = new File("C:\\Cry_ReportERP006.rpt");
/* Read a test document <em>doc</em> into a POI filesystem. */
final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(rep));
final DirectoryEntry dir = poifs.getRoot();
DocumentEntry dsiEntry = null;
try
{
dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
}
catch (FileNotFoundException ex)
{
/*
* A missing document summary information stream is not an error
* and therefore silently ignored here.
*/
}
/*
* If there is a document summry information stream, read it from
* the POI filesystem.
*/
if (dsiEntry != null)
{
final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
final PropertySet ps = new PropertySet(dis);
final DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
final SummaryInformation si = new SummaryInformation(ps);
/* Execute the get... methods. */
System.out.println(si.getAuthor());
推荐答案
请在此处找到示例代码 - Appache POI 如何
Please find the sample code here- Appache POI how to
简而言之,你可以监听MyPOIFSReaderListener
:
In brief, you can a listener MyPOIFSReaderListener
:
SummaryInformation si = (SummaryInformation)
PropertySetFactory.create(event.getStream());
String title = si.getTitle();
String Author= si.getLastAuthor();
......
并将其注册为:
POIFSReader r = new POIFSReader();
r.registerListener(new MyPOIFSReaderListener(),
"\005SummaryInformation");
r.read(new FileInputStream(filename));
这篇关于如何使用 Java/Apache POI 获取文件摘要信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文