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
View Answers
April 24, 2010 at 11:37 AM
Hi Friend,
Try the following code:
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
import java.awt.*;
import java.io.*;
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.*;
public class InsertJTable{
JTable table;
JButton button;
public static void main(String[] args) {
new InsertJTable();
}
public InsertJTable(){
JFrame frame = new JFrame("Getting Cell Values in JTable");
JPanel panel = new JPanel();
String data[][] = {{"Angelina","Mumbai"},{"Martina","Delhi"}};
String col[] = {"Name","Address"};
DefaultTableModel model = new DefaultTableModel(data, col);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
button=new JButton("Submit");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
int count=table.getRowCount();
try{
Object obj1 = GetData(table, 0, 0);
Object obj2 = GetData(table, 0, 1);
Object obj3 = GetData(table, 1, 0);
Object obj4 = GetData(table, 1, 1);
String value1=obj1.toString();
String value2=obj2.toString();
String value3=obj3.toString();
String value4=obj4.toString();
String data =value1+" "+value2+"\n"+value3+" "+value4;
writeToFile(data, "data.doc");
}
catch(Exception e){}
}
});
panel.add(pane);
panel.add(button);
frame.add(panel);
frame.setSize(500,500);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Object GetData(JTable table, int row_index, int col_index){
return table.getModel().getValueAt(row_index, col_index);
}
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());
}
}
}
Thanks
Related Tutorials/Questions & Answers:
export to word document - Java Beginnersexport 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
open word documentopen
word document how to open a
word document ??
Please go through the following link:
Java Read
word document file
The above link.... It will be helpful for you to read data from
word document Advertisements
open word documentopen
word document how to open a
word document ??
Please go through the following link:
Java Read
word document file
The above link.... It will be helpful for you to read data from
word document open word documentopen
word document how to open a
word document ??
Please go through the following link:
Java Read
word document file
The above link.... It will be helpful for you to read data from
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
convert word document to pdfconvert
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 processword 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
APACHE.POI -- Create word Document - Development processAPACHE.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
Creating MS Word document in java - StrutsCreating 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
JTextArea to Word DocumentJTextArea 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
Java Count word occurrence and export it to excel fileJava Count
word occurrence and
export it to excel file
Here is an example of scanning a text file in a local drive, and count
the frequency of each
word in the text file or you can say count the number or
occurrence of each
word upload and retrieve a word document - JSP-Servletupload and retrieve a
word document Hi,
I have a problem 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
exportexport how to
export tabled data in jsp into excel
open documentopen document open a
word document using jsp
Please go through the following link:
Java Read
word document file
The above link.... It will be helpful for you to read data from
word document PDF to Word Conversion - Java BeginnersPDF to
Word Conversion Hello,
Can we convert a PDF
document to Microsoft
word document thru Java.
If its not possible in Java, is it possible in any other language
MicroSoft wordMicroSoft word sir i want to develop an swing application like the microsoft
word Document.can you help me pls
export jsp page - JSP-Servletexport jsp page i want to
export jsp page in
word and pdf format... code that
export my jsp page in
word and pfd format.... Hi Friend,
Try the following code:
1)pdf.jsp:
Name
Address
Contact
Extracting equation from any documentExtracting equation from any document how can i extract equation from any
word document?
Hello Friend,
If you want to extract data from the
word file, then visit the following link:
Extract data from
word document NUMBER OF VOWELS IN A WORDNUMBER OF VOWELS IN A WORD WRITE A PROGRAM THAT WILL INPUT A
WORD THEN IT WILL DETERMINE THE NUMBER OF VOWELS PRESENT IN THE INPUTTED
WORD create MS Word in Java - Java Beginnerscreate 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... everywhere. But i need to write more to the
document like Table inserting values init
create html of word ,excel,ppt - JSP-Servletcreate html of
word ,excel,ppt Plzz tell me how to create html page of
word , excel ,ppt
document dynamically using jsp because in my project I have to store uploaded files as html page
Problem reading word fileProblem reading
word file Deepak you provide me code for extarcting equation from a
word file and also to write in a
word file.But when I again want to read preveously created
word file(created by your code) it gives an error
how to delete a letter in a word?how to delete a letter in a
word? how to delete a letter in a
word?
for example
if i enter= roseindia,
i want to delete 's',
then output= roeindia
ModuleNotFoundError: No module named 'export'ModuleNotFoundError: No module named '
export' Hi,
My Python... '
export'
How to remove the ModuleNotFoundError: No module named '
export'... to install padas library.
You can install
export python with following command
finout longest word in sentencefinout longest
word in sentence write a program , how to find out the longest
word in a sentence using java
Hi Friend,
Try...;
}
}
LongestWord(){
String
word = "";
for(int i=0;i<stringArray.length;i++){
if(i==0
print word with max vowelsprint
word with max vowels if suppose i hava entered a sentence and in that sentence i have to print a
word which has maximum vowels in it.... i have tried it but i am not getting it...please help
com in ms wordcom in ms word how to use com object to fetch data from ms
word and storing it into sql database
com in ms wordcom in ms word how to use com object to fetch data from ms
word and storing it into sql database
How to export grid into excelHow to
export grid into excel Hi, i created a grid panel i have to
export it to the excel. please help me by some sample code. thanks in advance. cool day dude
Display the data to MS word the database(say im searching using an id) and should display it on the ms
word , i want it to be in a good format.
FOr example my
word doc has to be
Name... a
word doc would help a lot!!
thank you