
How to write data or string in word file.

simply open the word document and type the string/text through keyboard..

Hi Friend,
Try this:
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class WriteInDocument{
static void writeToFile(String content, String path){
try{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
FileOutputStream out = new FileOutputStream(path);
fs.writeFilesystem(out);
out.close();
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[]args){
writeToFile("Hello World","c:/new.doc");
}
}
For the above code, you need POI api.
Thanks

Hi,
For the above code, poi-scratchpad-3.7-20101029.jar is needed.
Thanks

now how do i do it when there are more than one statements to print i mean, getting data from databse and using that resultset object to print the data.. im doing it in jsp like, A a=new A(); a.getName() a.getAge() a.getAddress ...like wise , i want these data set to be printed on the word document.. pls help with this

btw im gonna use servlet to print it on word... Krish

hi .... how to use servlet ???
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.