excel parsing and print data in the form of table

excel parsing and print data in the form of table

my reqment is i have to parse the excel and i need to print the data in the table by using swing jtable or else ....can u give the solution please....

View Answers

March 1, 2012 at 5:04 PM

import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class ExcelToJtable {
 public static void main(String[] args) {

  Vector headers = new Vector();
  Vector data = new   Vector();

    File file = new File("c:/data.xls");
    try {
    Workbook workbook = Workbook.getWorkbook(file);
      Sheet sheet = workbook.getSheet(0);
      headers.clear();
      for (int i = 0; i < sheet.getColumns(); i++) {
        Cell cell1 = sheet.getCell(i, 0);
        headers.add(cell1.getContents());
      }
      data.clear();
      for (int j = 1; j < sheet.getRows(); j++) {
      Vector d = new Vector();
      for (int i = 0; i < sheet.getColumns(); i++) {
      Cell cell = sheet.getCell(i, j);
          d.add(cell.getContents());
      }
      d.add("\n");
      data.add(d);
     }
    }
    catch (Exception e) {
         e.printStackTrace();
    }
    JTable table = new JTable();
    DefaultTableModel model = new DefaultTableModel(data,headers);
    int tableWidth = model.getColumnCount()* 150;
    int tableHeight = model.getRowCount()* 25;
     table.setPreferredSize(new Dimension(tableWidth, tableHeight));
     table.setModel(model);
     table.setAutoCreateRowSorter(true);
     model = new DefaultTableModel(data, headers);
     table.setModel(model);
     table.setEnabled(false);
     table.setRowHeight(25);
     table.setRowMargin(4);

     JScrollPane scroll = new JScrollPane(table);
     JFrame f=new JFrame();
     f.add(scroll);
     f.setSize(600, 600);
     f.setVisible(true);
  }
}

March 1, 2012 at 5:07 PM

For the above code, you need JExcel API.

Download JExcel API


March 1, 2012 at 6:50 PM

Thanks buddyyy.... can i edit the rows........... thanks in advance............









Related Tutorials/Questions & Answers:
excel parsing and print data in the form of table
excel parsing and print data in the form of table  my reqment is i have to parse the excel and i need to print the data in the table by using swing jtable or else ....can u give the solution please
Dynamic table data to Excel in JSP
Dynamic table data to Excel in JSP   Iam trying to export dynamic data to excel . But it is displaying only static data .Kindly help viewtrial.jsp...() { document.form1.des.disabled=0; } function view_Table() { } function
Advertisements
displaying data from ms excel in form.
displaying data from ms excel in form.  Hi all, I have a requirement as mentioned below: Requirement: I have stored some data in the ms excel... (for example). I need to display these data in a form. along with the actual picture
To save table format data in pdf/excel in jsp
To save table format data in pdf/excel in jsp  Hello, I am doing web... table. So my question is ,I want so save this html format data in pdf/excel format... can save html table data in pdf/excel format.Your inputs are valuable to me
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets... be loaded into an excel table automatically. i have created a dsn for excel... are not loading into excel table. would you help me in solving this problem
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet? ... be loaded into an excel table automatically. i have created a dsn for excel table... are not loading into excel table. would you help me in solving this problem
Convert the excel sheet data into oracle table through java or jsp
Convert the excel sheet data into oracle table through java or jsp  Hi Friends, Let me help this issue i am phasing Convert the excel sheet data into oracle table through java or jsp
print a form of *
print a form of *   * *** ***** ******* ********* ******* ***** *** *   Post the format properly
How to import data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase??
How to import data from sql server table into an excel file by creating... data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase?? There is a table in sql server having
How to download web page table data, export the table records in an excel file and save
How to download web page table data, export the table records in an excel file and save  i have a web page(.jsp) which contains the table of 4 to 5 columns. i m displaying the table using in my jsp page. below this table i want
Print Form - Java Beginners
Print Form  Hello Sir I have Created Admission Form when user fills data and submit that data to access database,then when i Click on PRINT Button I want to get Print of that forms Contents,How I can Do it with JAVA SWING,plz
Hi how to transfer table data from html page to excel sheet by using javascript .
Hi how to transfer table data from html page to excel sheet by using javascript .  html page to excel sheet by using javascript and i dont want to transfer all rows in table, i want to hide some rows in excel sheet. Please send
print form information when click on print button
print form information when click on print button   Sir,I desingn... please help for printing form information by clickin print button after submit data in the database
extract data from excel sheet to mysql
extract data from excel sheet to mysql  sir, i want to extract data from excel sheet and save the data in mysql5.0 database in the form of table
java parsing of data types
java parsing of data types  Why its not works? char ch; String s=* ch=Character.parseChar(s) program: char op; DataInputStream dis=new DataInputStream(System.in); System.out.print("Enter operator (+,-,*,/,%): "); op
Parsing Binary Data in PHP - PHP
Parsing Binary Data in PHP  Is there a better library for working with binary data in PHP
ModuleNotFoundError: No module named 'form-to-excel'
ModuleNotFoundError: No module named 'form-to-excel'  Hi, My... 'form-to-excel' How to remove the ModuleNotFoundError: No module named 'form-to-excel' error? Thanks   Hi, In your python
Fetching data from excel file on other website and display in interactive graph form
Fetching data from excel file on other website and display in interactive graph... which have zip files and excel files and they get updated everyday, so how can i pull data data from those and generate graphs out of it? I really need it urgently
exporting data to excel sheet - JDBC
exporting data to excel sheet  Sir i have already send request about... query in java swing program,i want to print the result about the query in excel...; Form(){ String data[][] = {{"",""}}; String col[] = {"Name
Exception during parsing a parameter from the form in JSP
Exception during parsing a parameter from the form in JSP  Exception during parsing params from a form? I get parameters from a html form. I parse the integer one in the JSP file, but I get exception. Is there anyway I can get
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
browse and submit the excel sheet into mysql as a table
browse and submit the excel sheet into mysql as a table  sir, i want to browse and after clicking a submit button, the data in the excel sheet should be stored in the mysql5.0 as a table
Export html data to excel
Export html data to excel  I am trying to export data from an html page to an excel sheet.Any advise
ModuleNotFoundError: No module named 'excel-form-builder'
ModuleNotFoundError: No module named 'excel-form-builder'  Hi, My... named 'excel-form-builder' How to remove the ModuleNotFoundError: No module named 'excel-form-builder' error? Thanks   Hi, In your
jsp data in excel - JSP-Servlet
in jsp using table. and getting this data from servlet which has query and this query data has come from beans and using beans i put it in excel jsp in table...jsp data in excel  i have create jsp page which has button
print the multiplication table up to one
print the multiplication table up to one  My problem is that I have...; System.out.println("Enter an integer to print it's multiplication table...(); System.out.println("Multiplication table of "+n+" is :-"); for ( c = 1 ; c <= 10
Retrieve Data into JTable and export it to Excel File
it into Vector which is then added to table. To export the table data to excel file, we... Java Retrieve Data into JTable and export it to Excel File... in the table and then export it to the Excel file. For this, we have created a table
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced'
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced' ...: ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced' How to remove the ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table'
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table'  Hi...: No module named 'sphinxcontrib-excel-table' How to remove the ModuleNotFoundError: No module named 'sphinxcontrib-excel-table' error? Thanks  
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced'
ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced' ...: ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced' How to remove the ModuleNotFoundError: No module named 'sphinxcontrib-excel-table-enhanced
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
dispalying arraylist values in table form
dispalying arraylist values in table form  My result is in arraylist and i want to display it in table form using iterator tag
how to print spark dataframe data
and i want to print all the data on console. How it can be done. how to print... is in "data" variable and you want to print it. Its simple and one line function to print...() function the print the data. Thanks
how to print spark dataframe data
and i want to print all the data on console. How it can be done. how to print... is in "data" variable and you want to print it. Its simple and one line function to print...() function the print the data. Thanks
how to display data in excel sheet?
how to display data in excel sheet?  According to the user Id,some... there will be a button called excel download,and if we click the button data... the button and to display the data in excel sheet
display:table export only data
display:table export only data  I am using display:table tag with attribute export="true". Using that I can export table data in excel. Here one of the column is in hyper link. But i need to export only data not html tag . Can
php import data from excel to mysql
php import data from excel to mysql  php import data from excel to mysql
jsp with excel sheet data uploading into database
jsp with excel sheet data uploading into database  how to upload data in excel sheet with jsp into oracle 10g database
Do data scientists use Excel?
Do data scientists use Excel?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Do data... that I can learn the topic "Do data scientists use Excel?". Also tell me
insert excel value in to oracle data base
then how excel data will mapp to oracle database table. My project requrement is when somebuddy fill a excel form then all form value will save on database table...insert excel value in to oracle data base  Hi All I am using
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form...)should automatically fill up in the form and on cliking print button it shoulg give
create folders and sub folders based on excel data
Current form this excel sheet how can i read the data line...create folders and sub folders based on excel data  Hi, i have a requirement that , read the data from excel sheet and based on that data i need
how to import excel sheet into mysql database and save it as a table in database
how to import excel sheet into mysql database and save it as a table in database  sir, i want to import an excel sheet into a MySQL database and after importing it i want to store the excel sheet as a table in database
Process HTML FORM data
Process HTML FORM data  Can a JSP page process HTML FORM data?   Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through Text File   Hello Sir ,I have Designed Employee Details Form using java swing components Now i want to print contents which is filled by employee,How i can Print it,and also i want print
validating a form before data is entered.
validating a form before data is entered.  How can I avoid validating a form before data is entered
ModuleNotFoundError: No module named 'django-excel-data-sync'
ModuleNotFoundError: No module named 'django-excel-data-sync'  Hi...: No module named 'django-excel-data-sync' How to remove the ModuleNotFoundError: No module named 'django-excel-data-sync' error? Thanks   Hi

Ads