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



Home Answers Viewqa Java-Beginners excel parsing and print data in the form of table
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sathish gollapally
excel parsing and print data in the form of table
3 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


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....


Advertisement
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
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
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 - 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
Parsing Binary Data in PHP - PHP
Parsing Binary Data in PHP  Is there a better library for working with binary data in PHP
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
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
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
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
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
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
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
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
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
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
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
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
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
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
 

 

 

DMCA.com