java - How to save a word docx file using Apache poi. Change to saxon9he instead of saxon9pe -


i use latest apache poi 3.13-beta1 version. , error like:

exception in thread "main" org.apache.poi.openxml4j.exceptions.openxml4jruntimeexception: fail save: error occurs while saving package : null @ org.apache.poi.openxml4j.opc.zippackage.saveimpl(zippackage.java:507) @ org.apache.poi.openxml4j.opc.opcpackage.save(opcpackage.java:1441) @ org.apache.poi.poixmldocument.write(poixmldocument.java:202) caused by: java.lang.nullpointerexception     @ com.saxonica.config.verifier.loadlicense(verifier.java:141)     @ com.saxonica.config.professionalconfiguration.loadlicense(professionalconfiguration.java:391)     @ com.saxonica.config.professionalconfiguration.islicensedfeature(professionalconfiguration.java:367)     @ net.sf.saxon.identitytransformer.transform(identitytransformer.java:36)     @ org.apache.poi.openxml4j.opc.streamhelper.savexmlinstream(streamhelper.java:80)     @ org.apache.poi.openxml4j.opc.internal.marshallers.zippartmarshaller.marshallrelationshippart(zippartmarshaller.java:174)     @ org.apache.poi.openxml4j.opc.zippackage.saveimpl(zippackage.java:468) 

my code here:

string filepath = "d:\\doc\\file1.docx" try {     fileinputstream fis = new fileinputstream(filepath);     xwpfdocument xdoc = new xwpfdocument(opcpackage.open(fis));      system.out.println("here can read file , work on it");      string filepathout = filepath.replace("file", "file_result");     xdoc.write(new fileoutputstream(new file(filepathout))); } catch (filenotfoundexception e) {     e.printstacktrace(); } catch (ioexception e) {     e.printstacktrace(); } catch (invalidformatexception e) {     e.printstacktrace(); } 

i want replacement , save file back.

edit 1. looks apache poi works our saxon9pe lib requires licence. can set avoid saxon9pe in poi , use saxon9he?

thanks.

here how open , close docx files:

final xwpfdocument docx = new xwpfdocument(new fileinputstream(new file(infilenamestring))); final fileoutputstream out = new fileoutputstream(outfilenamestring); docx.write(out); out.close(); docx.close(); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -