There is a simple way of extracting data which I think only fetch it as a text ( using toSting()
method), but I want to fetch data according to specified column or row’s name.
Following is a sample code which simply print the content of the MS Excel along with its metadata (avoid this part).
It uses tika-app-1.13.jar (if you want to run this code add this library)
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, SAXException {
//detecting the file type
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
FileInputStream inputstream = new FileInputStream(new
File("C:\\Users\\Username\\IdeaProjects\\Tika\\src\\example.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));
}
}
}
example.xlsx contains the data (kindly go through the link to see the data)
What I want to ask if I want to extract / fetch only the data from let say, the column of "age" using Apache Tika in Java, is there any way of doing it?