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



Home Answers Viewqa Swing-AWT create , edit MS WORD like document file using Java Swing

Have Programming Question? Ask it here!
 
 
 


akshay
create , edit MS WORD like document file using Java Swing
1 Answer(s)      4 years and 5 months ago
Posted in : Swing AWT


In my program I have JTextArea. Text in JTextArea can be set to
selected font, font style etc. I want this text in JTextArea to
be saved to MS WORD like document file. Then how should I create,
edit , retrieve this document file?

I am using Java SWING.

Plz. email your answer at : axaygokhale@yahoo.com

Advertisement
View Answers

March 18, 2010 at 3:59 PM


Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
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 TextAreaInDocument extends JFrame{
JTextArea area;
JScrollPane pane;
JButton b1;
File file = new File("C:/New.doc");

private static void writeDoc(String FileName,String content){
try{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
FileOutputStream out = new FileOutputStream(FileName);

fs.writeFilesystem(out);
out.close();
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
}

TextAreaInDocument(){
area=new JTextArea(10,50);
area.setFont(new Font("courier New",Font.BOLD,12));
pane=new JScrollPane(area);
b1=new JButton("Create");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String text=area.getText();
String f=file.getPath();
writeDoc(f,text);
area.setText("");
}
});

JPanel p=new JPanel();
p.add(pane);
p.add(b1);
add(p);
setVisible(true);
pack();
}
public static void main(String[]args){
TextAreaInDocument doc=new TextAreaInDocument();
}
}

For more information, visit the following link:

http://www.roseindia.net/tutorial/java/poi/readDocFile.html

Thanks


Related Tutorials/Questions & Answers:
create , edit MS WORD like document file using Java Swing - Swing AWT
create , edit MS WORD like document file using Java Swing   In my..., font style etc. I want this text in JTextArea to be saved to MS WORD like document file. Then how should I create, edit , retrieve this document file
Edit word document Headers and Footers using POI Library in java?
Edit word document Headers and Footers using POI Library in java?  Hi All, I need code to modify the Header and Footer contents of a ms-word template using POI or JACOB libraries. Could any one help me? Thanks Advance
Advertisements
create, edit ,open simple documents using java - Swing AWT
want to use Java Swing or JSP? Do you want to create word document file...create, edit ,open simple documents using java   In my program I have a text area.How to create document which will contain text in text
java code to open and display MS-word document
java code to open and display MS-word document  java code to open and display MS-word document
Creating MS Word document in java - Struts
Creating MS Word document in java  I have one template in MS Word which has some content. Now i want to read this doc file and wants to add some content and also i need to set header and footer in doc file. That is, reading
Using poi hwpf,how to create table in word document. - Java Beginners
Using poi hwpf,how to create table in word document.  Can you please tell me how to create a table in the word document in java using Apache poi hwpf.its very urgent.Please send some sample code.Thanks in advance
create MS Word in Java - Java Beginners
create MS Word in Java  Hi, Could any one please post the code which creates the word document having different paragraphs and two tables. i have... which creates MS Word in Java
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
edit msword file - using java - Java Beginners
edit msword file - using java  I want to edit ms word file. That is input file font style is times new romen and font size is 12. I want the output file font style is bookman old style and size is 20. How to possible java
APACHE.POI -- Create word Document - Development process
the code which creates MS Word in Java... Raghu J...APACHE.POI -- Create word Document  Hi, Could any one please post the code which creates the word document having different paragraphs and two
How to hide text in Word Document using Apache POI library
How to hide text in Word Document using Apache POI library  Is it possible to hide text in MS Word Document using Apache POI library? If yes, please let me know how. I am able to create and read the document using POI library
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
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
export to word document - Java Beginners
export to word document  hi sir,when i am click on a button under the jtable,for example (print button),then i want to print that jtable in word document,automatically,plz provide program sir  Hi Friend, Try
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... the user typed his/her name, it will check the name in the text file. To check
Create - XML File (Document)
Create - XML File (Document)     ... document using the DOM APIs. This XML document uses  1.0 version  and UTF-8... file with its version and encoding.  Here is Java File: CreatXMLFile.java
JTextArea to Word Document
that enable us to perform read, write operations with ms word file. Here we are going to write the data into word document file through a swing component. You can... saved in the word file using POI classes. And you can view your file by clicking
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated... mean? Does it an inbuilt class file or should i create such a class file? I am
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
edit the flash video file using html5
edit the flash video file using html5  hi iam vivek i have a flash file i want to edit it with html5 please reply
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
how to store image file and videofile in ms access database using java? - JDBC
how to store image file and videofile in ms access database using java?  how to store image file and video file in ms access database using java
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
Display the data to MS word
Display the data to MS word  i want help with displaying data on to ms word.When i click the button my web page my servlet should get the data from the database(say im searching using an id) and should display it on the ms word
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
Java Swing Create XML file
Java Swing Create XML file In this tutorial, you will learn how to create XML file using swings. Here is a code that accepts the data from the user through swing components and display it in xml file. We have created textfields
How to create Multiple Frames using Java Swing
Multiple Frames in Java Swing In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another... display a JFrame-like window within another window. It provides many
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm... by searching the JAVA and .net words present in the files..if JAVA word is present means it has to be separated in separate DATABASE folder like that for .net
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm... by searching the JAVA and .net words present in the files..if JAVA word is present means it has to be separated in separate DATABASE folder like that for .net
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
viewing the ms word in print layout from jsp - Java Beginners
viewing the ms word in print layout from jsp  Hi all, I am trying to export ms word from jsp in print layout format.I used the code for converting into ms word but it is opening in web layout. My requirement
Write String in Word document
Write String in Word document  How to read and write strings in word document
Java Read .doc file using POI library
Java Read .doc file using POI library In this section, you will learn how to read the word document file using POI library. The class HWPFDocument throw all of the Word file data and the class WordExtractor extract the text from
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
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
store form data into word document
store form data into word document  i want form page data, ex username phone number.. to store it in a word document file
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 remove paragraph from ms word
How to remove paragraph from ms word  Hi! I am using MS Word to edit my text but somehow i get paragraph sign on every line of my text. So, can any one please tell me how to remove paragraph from ms word?   CTRL+SHIFT+8
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?   How to set a microsoft word document PASSWORD by using Visual Basic 2008 express
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
Open Text or Word Document on JButton Click in Java - Java Beginners
Open Text or Word Document on JButton Click in Java  How to open Word document or Text File on JButton Click in java  Hi Friend, Try the following code: import java.io.*; import java.util.*; import javax.swing.
java to MS Access conectivity - Swing AWT
java to MS Access conectivity  give me source code to stored...(*.mdb) 5. Select database name and Create the DSN name (e.g emp) 6. Click "Ok" and then compile the following java program. import java.awt.*; import
Advertisements
 

 

 

DMCA.com