extract data from excel and display it in browser(inthe form of table) with some modifications (by adding heaer and footer) using JSP,ApachePOI

extract data from excel and display it in browser(inthe form of table) with some modifications (by adding heaer and footer) using JSP,ApachePOI

Pplease anybody post a jsp program that reads data from microsoft excel and displays it in a table formatin the browser....(using apache tomcat poi) ......my project is that i should enter an excel file name and it should read that file and display in the form of table in webrowser by using jsp,apachetomcat,poi please.please.please....... post as soon as possible.......

thanks in advance......hoping for your earliest replies

View Answers

December 27, 2010 at 12:18 PM

Hi Friend,

Try the following code:

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
    <table border="1">

<%
 short a=0;
  short b=1;
  short c=2;
  short d=3;
  int i=0;
   String   value1="", value2="",value3=" ", value4="";
    String filename ="C:/hello.xls"; 
    if (filename != null && !filename.equals("")) {
    try{
    FileInputStream fs =new FileInputStream(filename);
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    for (int k = 0; k < wb.getNumberOfSheets(); k++){
        int j=i+1;



    HSSFSheet sheet = wb.getSheetAt(k);
    int rows  = sheet.getPhysicalNumberOfRows();
    for (int r = 0; r < rows; r++){
    HSSFRow row   = sheet.getRow(r);
    int     cells = row.getPhysicalNumberOfCells(); 
      out.write("<br>");

    HSSFCell cell1  = row.getCell(a);

      value1 = cell1.getStringCellValue();
      HSSFCell cell2  = row.getCell(b);
        value2 = cell2.getStringCellValue();
         HSSFCell cell3  = row.getCell(c);
         value3 = cell3.getStringCellValue();
          HSSFCell cell4  = row.getCell(d);
          value4 = cell4.getStringCellValue();
    %>
    <tr><td><%=value1%></td><td><%=value2%></td><td><%=value3%></td><td><%=value4%></td></tr>
    <%
    }
        i++;
    }
    }
    catch(Exception e){
        System.out.println(e);
    }
    }
    %>
    </table>

Thanks


December 28, 2010 at 12:17 AM

Thanks for your valuable code...But i have two problems with the above code.

1.I have different number of sheets and in each sheet number of columns(i.e. we have fistname,lastname,id in 1 sheet and firstname,lastname,fullname,id in another sheet).the above code displays only concatenation of two sheets cells having same number of columns.....

2.next it also does not display if there is nothing in a cell....i.e., if a particular row in an excel file does not have anything in it...then even the next rows are also not displayed.....

My requirement is to display all the data from all sheets (including null and not null)in the form of tables....

please send the revised code..... Thank you very very much.....









Related Tutorials/Questions & Answers:
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
how to display the data from excel to webpage
how to display the data from excel to webpage  Hi, I need help... that reads the excel file and store data into table. <%@page import="java.io.*"%>... search for the value 4024 in a excel file and to display the remaining values
Advertisements
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
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
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 form  Hello, I am making a website using HTML and CSS, I am done... pull data data from those and generate graphs out of it? I really need it urgently
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... at line: 113 in the jsp file: /Cat1.jsp The local variable v_RGPC may not have
extract data from HTML
extract data from HTML  how to write the coding for to extract data from html tags like(h3,p) and then extracted data should be stored in data base? can anybody tell me how to write the coding
how to display data in excel sheet?
how to display data in excel sheet?  According to the user Id,some links will be generated from the database,and if we click a link,data would... the button and to display the data in excel sheet
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
How to export data from html to excel sheet by using java
How to export data from html to excel sheet by using java   How to export data from html to excel sheet by using java
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java    How to export data from html file to excel sheet by using java
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... upload excel file and update database using JSP ? Thanks in Advance
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java   reading the data from Html file
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/servlet-jsp-data
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
extract data fom table when a button is clicked in front end page using mysql5.0 and tomcat6.0
extract data fom table when a button is clicked in front end page using mysql5.0 and tomcat6.0   sir, i want to extract data from table which... this will be helpful for you http://roseindia.net/jsp/servlet-jsp-data-list.shtml http
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
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
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
how to display the excel file in the web browser.
how to display the excel file in the web browser.  > %@ page.../vnd.ms-excel" > %> <%@ page import="java.io.*" %> <% >... FileOutputStream > ("c:\\excel\\aqtemplate.xlsx"); > wb.write
Insert data in Excel File from Database using JSP
Insert data in Excel File from Database  using JSP ... developed a application to insert data  in excel file from database in JSP. We... will retrieve the data from database, create an excel file and data insert
Exporting to excel using display tag?
Exporting to excel using display tag?  Hai , I am implementing pagination in struts.It has export to excel option.When I am clicking... to excel option.Please help me on this. Regards, N.Santosh
Html form using JavaScript to display the table content
Html form using JavaScript to display the table content  HI... extract the single xml and store it in a SQL server db. I have done these part. Now I want to write a Html JavaScript coding to display the content from database
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
Python extract data from JSON
Python extract data from JSON  Hi, I have a program that reads json data from third part web service. My webservice is returning json and I am..., For parsing and getting the data from JSON. You can use the json library which ships
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
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
Display Blob(Image) from Mysql table using JSP
Display Blob(Image) from Mysql table using JSP In this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores... Also : Insert Blob(Image) in Mysql table using JSP Download Source CodeADS
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how to display that? For example i have some number of books in database but i want
filter and display html table data using ajax - Ajax
filter and display html table data using ajax  Hi i am stuck up... to DisplayCategory.jsp i want to display the data retrieved from the session in a 2d array on DisplayCategory.jsp in the form of the html table using responseText. how to do
How to export data from database to excel sheet by using java in standalone project
How to export data from database to excel sheet by using java in standalone project  How to export data from database to excel sheet by using java in standalone project
How to get data from Excel sheet - Struts
How to get data from Excel sheet  Hi, I have an excel sheet with some data(including characters and numbers). Now i want read the data from excel sheet and display in console first then later insert this data into database
How to display data in form using aryylist in struts - Java Beginners
How to display data in form using aryylist in struts  Hi, I want to display data using arraylist in struts pls help me Its urgent
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
How to export data from database to excel sheet by using java swing in standalone project - Java Beginners
How to export data from database to excel sheet by using java swing... from u to solve my problem. my problem is i don know how to export data from database to excel sheet by using java swing in standalone project.I get solution from
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which...://www.roseindia.net/answers/viewqa/JSP-Servlet/28123-write-excel-file-into-the-oracle
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
Dynamic retrieval od data from database and display it in the table at jsp
Dynamic retrieval od data from database and display it in the table at jsp ...; Here is a jsp code that retrieves the data from the database and display... the details of 20 members in a table format at jsp page by dynamically retrieving
php import data from excel to mysql
php import data from excel to mysql  php import data from excel to mysql
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
How to Extract row from table view using JSP Code - Java Beginners
How to Extract row from table view using JSP Code  Hi Friends... to java world and trying to design a web page using NetBeans IDE 6.8. My problem exist with retrival of row from a table on click of link. Table Structure
Retrieving specific data from excel
Retrieving specific data from excel  Hello everyone, i have written a simple code to retrieve data from excel sheet and working fine, the excel file... first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0
Display Data from Database in JSP
;head> <title>display data from the table using jsp</title> <...; <head> <title>display data from the table using jsp</title>... Display Data from Database in JSP   
how to display the selected row from the data table in model panel ??
how to display the selected row from the data table in model panel ??  the below displayed is my datatable:tableDatas.xhtml <rich:dataTable value="#{tableRecordBean.dataList}" var="dataItems" onRowClick="#{rich

Ads