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



Home Answers Viewqa Struts store form data into word document
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


suresh kumar
store form data into word document
1 Answer(s)      2 years and 10 months ago
Posted in : Struts


i want form page data, ex username phone number.. to store it in a word document file


Advertisement
View Answers

December 28, 2011 at 12:07 PM


We are providing you a program that will store java swing form data into word file using POI API.

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
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.*;
class Form extends JFrame{

JButton ADD;
JPanel panel,pan;
JLabel label1,label2,label3,label4;
final JTextField text1,text2,text3,text4;
Form() {
label1 = new JLabel();
label1.setText("Student Id:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("Name:");
text2 = new JTextField(20);

label3 = new JLabel();
label3.setText("Address:");
text3 = new JTextField(20);

label4 = new JLabel();
label4.setText("City:");
text4 = new JTextField(20);
ADD=new JButton("Add");

panel=new JPanel(new GridLayout(5,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(ADD);
add(panel,BorderLayout.CENTER);
setTitle("FORM");

ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String data="STUDENT ADMISSION FORM\n\n\nSTUDENT ID: "+text1.getText()+"\nNAME: "+text2.getText()+"\nADDRESS: "+text3.getText()+"\nCITY: "+text4.getText();
writeToFile(data, "Employee.doc");
try{
Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /C start Employee.doc");
}
catch(Exception e){}
}
});
}
private 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());
}
}
}
class InsertToFile{
public static void main(String arg[]) {
try
{
Form frame=new Form();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e)
{}
}
}

Hope that it will be helpful for you.



Related Tutorials/Questions & Answers:
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
open word document
. It will be helpful for you to read data from 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
Advertisements
open word document
. It will be helpful for you to read data from 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
open word document
. It will be helpful for you to read data from 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
Write String in Word document
Write String in Word document  How to read and write strings in word document
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
JTextArea to Word Document
JTextArea to Word Document Jakarta POI has provided several classes 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
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 PDFs also. I got a code like the below, and i am unable to download the office
word document reading - Development process
word document reading  I am in the midst of reading a word document while reading charts(EMF or WMF) pictures i am not able to do so can u suggest one class for this to accomplish
POI Word document (Letter Template)
POI Word document (Letter Template)  Dear Team, i need code for generating word document(letter format). i am unable to get the code for formats, font settings, letter type settings. please help me for the same. Thanks
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
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
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
upload and retrieve a word document - JSP-Servlet
with uploading a word document to My sql database to a BLOB data type variable. And also unable to retrieve the word document from database. I am writing the code...("multipart/form-data") >= 0)) { DataInputStream in = new DataInputStream
APACHE.POI -- Create word Document - Development process
APACHE.POI -- Create word Document  Hi, Could any one please post the code which creates the word document having different paragraphs and two... this code everywhere. But i need to write more to the document like Table inserting
store and retrieve data
store and retrieve data  sir,i want to store the entering data in a word file and retrieve it when i need.i am try to develop a video portal.in which... Write data into word file For this, poi-scratchpad-3.7-20101029.jar is needed
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
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 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
to store form vaues in database - JDBC
to store form vaues in database  sir i have created one form with two... in textboxea the data must be stored in MYSQLdatabase please provide the code   Hi friend, Code to insert the data into database
Store ResultSt Data in a Map
Store ResultSt Data in a Map  i want to store data in a hash Map .Please solve my problem as soon as possible
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... org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.*; class Form extends
iPad App to store data
iPad App to store data  Hi, How to add data support iPad application? Thanks
store pagination form fields - Struts
store pagination form fields   hi,iam working online exams project . my intention is to save data that has been asnwered by client/student into db... to populate all the data that has been answered by client intothe db. how can i
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
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
Java Xml Data Store
be followed up and/or purchased. You will need to store the data in a local binary... the implementation needs to change later on (perhaps they might decide to store the data...Java Xml Data Store  I have to do this project and i'm finding it so
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
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
 

 

 

DMCA.com