gpt4 book ai didi

java - 如何使用 Java/Apache POI 获取文件摘要信息

转载 作者:行者123 更新时间:2023-12-04 05:29:05 33 4
gpt4 key购买 nike

我正在尝试使用 JAVA 从文件中获取摘要信息,但找不到任何内容。我试过 org.apache.poi.hpsf.* .

我需要作者、主题、评论、关键字和标题。

       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 how to

简而言之,您可以收听 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 - 如何使用 Java/Apache POI 获取文件摘要信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861054/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com