Hi,
Im working on creating new doc using POI. i found a sample code:
import java.util.*;
import java.io.*;
import java.lang.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
public class test4 {
private static String _blankFile = "blank.doc";
private static void copyBlankHWPF (String name) {
try {
HWPFDocument doc = new HWPFDocument(new
FileInputStream(_blankFile));
OutputStream out = new FileOutputStream(name);
doc.write(out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String [] args){
String generatedFile =
args[1].substring(0,args[1].length()-3)+"-generated.doc";
try {
copyBlankHWPF(generatedFile);
HWPFDocument templateFile = new HWPFDocument(new
FileInputStream(args[0]));
HWPFDocument blankFile = new HWPFDocument(new
FileInputStream(_blankFile));
OutputStream out = new FileOutputStream(generatedFile);
Range blankRange = blankFile.getRange();
Range templateRange= templateFile.getRange();
String templateContent = templateRange.text();
templateContent =
templateContent.replaceAll(string1,string2);
blankRange.insertBefore(templateContent);
blankFile.write(out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
when i run the code it will throw an exception:
java.io.FileNotFoundException: blank.doc
i created a blank.doc in my current directory but i got this error when i
run again the application:
Error getting property set with name ♣DocumentSummaryInformation
java.io.FileNotFoundException: no such entry: "♣DocumentSummaryInformation"
Error getting property set with name ♣SummaryInformation
java.io.FileNotFoundException: no such entry: "♣SummaryInformation"
Error getting property set with name ♣DocumentSummaryInformation
java.io.FileNotFoundException: no such entry: "♣DocumentSummaryInformation"
Error getting property set with name ♣SummaryInformation
java.io.FileNotFoundException: no such entry: "♣SummaryInformation"
i dont know what happen here, i found a site:
http://java.sys-con.com/read/45846.htm that state: The POI distribution
comes with one called "blank.doc."
But i coudn't found it in distribution folder.
Does anyone know how to make this code running? I am new to all of this.
Thanks in advance.
--
View this message in context:
http://www.nabble.com/Creating-new-word-doc-with-POI-tf3038842.html#a8445730
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/