Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Write data in doc file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


babu
Write data in doc file
6 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


How to write data or string in word file.


Advertisement
View Answers

February 4, 2011 at 12:29 PM


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



February 4, 2011 at 12:52 PM


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



February 4, 2011 at 12:59 PM


Hi,

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

Thanks



July 20, 2011 at 3:07 PM


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



July 20, 2011 at 3:09 PM


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



September 16, 2011 at 12:44 AM


hi .... how to use servlet ???



Related Tutorials/Questions & Answers:
Write data in doc file
Write data in doc file  How to write data or string in word file
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
Advertisements
doc file - Java Beginners
doc file   i want to read .doc file ?....it is a part of my project plz help. if possible , can anyone give me the code
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
convert a file .doc to .zip
convert a file .doc to .zip  hiii, I uploaded a file with extension .doc now i required with .zip   Hi Friend, Try the following code...;TITLE>Display file upload form to the user</TITLE></HEAD> <
read doc and docx file in javascript
read doc and docx file in javascript  How i read doc and docx file in javascript
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
serch document from .doc and .docx file
serch document from .doc and .docx file  how to find particular word from .doc and .docx file and that date insert into a data base
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?  import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFileExample
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java... throw all of the Word file data and the class WordExtractor extract the text
how to store/retrieve doc file - Java Beginners
how to store/retrieve doc file  i want to wirte a code that stores/ retrieves .doc files to the mysql database using jsp pages... can anyone help me with the code?  Use this stuff inside your jsp page for store file
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...{ String sCurrentLine; // Groped file name (Suresh.txt...(Exception ex){ //File file = new File("D:\\groupby.txt
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...{ String sCurrentLine; // Groped file name (Suresh.txt...(Exception ex){ //File file = new File("D:\\groupby.txt
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...{ String sCurrentLine; // Groped file name (Suresh.txt...(Exception ex){ //File file = new File("D:\\groupby.txt
openning the pdf or doc file in same jsp
openning the pdf or doc file in same jsp   **how to open the pdf and doc file in same jsp after clicking the link or button (which is with out moving to the next page). will some body help me on this @simple format please
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
Retrieve data from the database and write into ppt file
Java Retrieve data from the database & write into ppt file In this section, we are going to retrieve data from the database and write into the .ppt file. For this purpose, we have used Jakarta POI api to create a .ppt file. The class
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import...{ document.close();} %> </body> I added itextpdf jar file to the libraries.the pdf file are not opened when i execute the program.please send the code
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import...{ document.close();} %> </body> I added itextpdf jar file to the libraries.the pdf file are not opened when i execute the program.please send the code
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import...{ document.close();} %> </body> I added itextpdf jar file to the libraries.the pdf file are not opened when i execute the program.please send the code
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import...{ document.close();} %> </body> I added itextpdf jar file to the libraries.the pdf file are not opened when i execute the program.please send the code
ResultSet Object data to Ms-Word Doc
ResultSet Object data to Ms-Word Doc   help me , i don't know how to write data from oracle database into MSWord document using servlet or jsp
How to read a line from a doc file
How to read a line from a doc file  How to read a line from a doc file   Hi Friend, To run the following code, you need to download POI... void main(String[] args) { File file = null; WordExtractor extractor = null
Retrieve Data from the database and write into excel file
Retrieve Data from the database and write into excel file. In this section, we are going to retrieve data from the database and write into the excel file...); fileOut.close(); System.out.println("Data is saved in excel file
Open a .doc file by click on the link using struts - Struts
Open a .doc file by click on the link using struts   I want to open a doc extension file when i click a link on jsp page .I know only about which is write in web.xml but not exactly know how i do this.Plz any one can help me
write data to plist
write data to plist  How to write data to plist file in XCode
Merge multiple jasper file to one word Doc using java
Merge multiple jasper file to one word Doc using java   how to Merge multiple jasper file to one word Doc using java
how to convert doc file into html using java swing
how to convert doc file into html using java swing  i want to convert doc file into html and display it on jtextarea please help me and give the sample code
Sort file data and write into another file
Sort file data and write into another file By sorting, you can arrange the data into meaningful order and analyze it more effectively. Here we have one file... and grade. The data is not properly arranged in the file. Now, we have to display
Java Write to properties file
. Here we are going to create a .properties file and write data...Java Write to properties file In this section, you will learn how to write data to properties file.  The properties file is basically used to store
C file write example
C file write example       This section demonstrates you to write the data into the file. Here we are using the library function fwrite() to write the data into the file. You
Advertisements
 

 

 

DMCA.com