- TIKA 教程
- TIKA - 主頁
- TIKA - 概述
- TIKA - 架構
- TIKA - 環境
- TIKA - 引用 API
- TIKA - 檔案格式
- TIKA - 文件型別檢測
- TIKA - 內容提取
- TIKA - 元資料提取
- TIKA - 語言檢測
- TIKA - GUI
- TIKA 有用資源
- TIKA - 快速指南
- TIKA - 有用資源
- TIKA - 討論
TIKA - 提取 MS-Office 檔案
以下是從 Microsoft Office 文件中提取內容和元資料的程式。
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.microsoft.ooxml.OOXMLParser;
import org.apache.tika.sax.BodyContentHandler;
import org.xml.sax.SAXException;
public class MSExcelParse {
public static void main(final String[] args) throws IOException, TikaException {
//detecting the file type
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
FileInputStream inputstream = new FileInputStream(new File("example_msExcel.xlsx"));
ParseContext pcontext = new ParseContext();
//OOXml parser
OOXMLParser msofficeparser = new OOXMLParser ();
msofficeparser.parse(inputstream, handler, metadata,pcontext);
System.out.println("Contents of the document:" + handler.toString());
System.out.println("Metadata of the document:");
String[] metadataNames = metadata.names();
for(String name : metadataNames) {
System.out.println(name + ": " + metadata.get(name));
}
}
}
將上述程式碼另存為 MSExelParse.java,並使用以下命令透過命令提示符對其進行編譯 −
javac MSExcelParse.java java MSExcelParse
在此處,我們將傳遞以下示例 Excel 檔案。
給定的 Excel 檔案具有以下屬性 −
在執行上述程式後,將獲得以下輸出。
輸出 −
Contents of the document: Sheet1 Name Age Designation Salary Ramu 50 Manager 50,000 Raheem 40 Assistant manager 40,000 Robert 30 Superviser 30,000 sita 25 Clerk 25,000 sameer 25 Section in-charge 20,000 Metadata of the document: meta:creation-date: 2006-09-16T00:00:00Z dcterms:modified: 2014-09-28T15:18:41Z meta:save-date: 2014-09-28T15:18:41Z Application-Name: Microsoft Excel extended-properties:Company: dcterms:created: 2006-09-16T00:00:00Z Last-Modified: 2014-09-28T15:18:41Z Application-Version: 15.0300 date: 2014-09-28T15:18:41Z publisher: modified: 2014-09-28T15:18:41Z Creation-Date: 2006-09-16T00:00:00Z extended-properties:AppVersion: 15.0300 protected: false dc:publisher: extended-properties:Application: Microsoft Excel Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Last-Save-Date: 2014-09-28T15:18:41Z
廣告