I am trying to edit the word document(.doc/.docx) content using apache poi jar, But i unable to edit the document.
Is there any possible way to edit word document using poi?
Hi ,thanks for reply. Here i am posting the problem i faced while writing the .doc file.
public class Headers {
public void newWordDoc(Stri ng baseFilename, String outputFilename) {
POIFSFileSystem fs = null;
HWPFDocument doc = null;
try {
fs = new POIFSFileSystem (new FileInputStream (baseFilename)) ;
doc = new HWPFDocument(fs );
// Get the Range object encapsulating the text for the entire document.
Range range = doc.getRange();
public class Headers {
public void newWordDoc(Stri ng baseFilename, String outputFilename) {
POIFSFileSystem fs = null;
HWPFDocument doc = null;
try {
fs = new POIFSFileSystem (new FileInputStream (baseFilename)) ;
doc = new HWPFDocument(fs );
// Get the Range object encapsulating the text for the //entire document.
Range range = doc.getRange();
if((range.text( )).contains("SA SI"))
range.replaceTe xt("SASI", "${56565656 }");
doc.write(new FileOutputStrea m(outputFilenam e));
}
catch(Exception ex) {
System.out.prin tln("Caught an: " + ex.getClass().g etName());
System.out.prin tln("Message: " + ex.getMessage() );
System.out.prin tln("Stacktrace follows........ .....");
ex.printStackTr ace(System.out) ;
}
}
public static void main(String[] args) {
Headers wt = new Headers();
wt.newWordDoc("/home/bvritic/Desktop/docs/LatestResume.do c", "/home/bvritic/Desktop/docs/LatestResume.do c");
}
}
I am trying to replace the string SASI with "${56565656 }". It is working fine for first time.But i run the same program second time
i got the following error:
Comment