Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Write data in doc file

Ads

 
 

Share on Google+Share on Google+

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

How to write data or string in word file.

Ads
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 ???


Ads









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
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
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
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <[email protected] 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, <[email protected] 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, <[email protected] 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, <[email protected] 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
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 plist
write data to plist  How to write data to plist file in XCode
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
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
read doc and docx file in javascript
read doc and docx file in javascript  How i read doc and docx file in javascript
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
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
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
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> <
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
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
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 write in File in Java
How to write in File in Java  Hi, How to write in File in Java..., For writing some data in the file we require some class file, objects... the (BufferedReader) constructor. So that we write some data suing
Java write to file
Java write to file  How to write to a file in Java? Is there any... files. You can easily use the the FileWriter and BufferedWriter to write data to a text file. Here is the examples: Example program to write to file. File
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java... will be able to use OutputStreamWriter on a FileOutputStream classes to write data to a file from Java program. To write the Java Write To File we will use two
How to write a file in Java?
How to write a file in Java? To write a file in Java use the class FileWriter... a FileWriter object with a given file object. Using this constructor data is written... or False. BufferedWriter: The BufferWriter class is used to write data from
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 write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
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
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks