Java Spring, extract a certain textbox from .docx

135 Views Asked by At

Right now, I'm using apache.poi in my spring webapp to extract the whole content of a previously uploaded .docx.

public Details getDetailsFromFile(String file) throws IOException, InvalidFormatException {
    Details details = new Details();
    FileInputStream fis = new FileInputStream(env.getProperty("rootlocation") + "/" + file);
    XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
    XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
    details.setText(extractor.getText());

    return details;
}

Is there a way to assign something like an ID to a textbox in the .docx and extract only that, instead of getting the whole content of the .docx and split it using application logic? How would you assign the ID in the .docx and then extract it using Java?

0

There are 0 best solutions below