read excel data from jsp

read excel data from jsp

Hi

how to read excel file from jsp? Excel file is created manually entered data having many sheets? and read the entire sheet and also edit with jsp?

pls suggest me?

View Answers

May 31, 2010 at 5:13 PM

Hi Friend,

1)excel.jsp:

<%@ 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"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
try{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet1 = hwb.createSheet("Sheet1");
HSSFSheet sheet2 = hwb.createSheet("Sheet2");
HSSFRow rowhead = sheet1.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Roll No");
rowhead.createCell((short) 1).setCellValue("Name");
rowhead.createCell((short) 2).setCellValue("Marks");
rowhead.createCell((short) 3).setCellValue("Grade");

HSSFRow row1 = sheet1.createRow((short)1);
row1.createCell((short)0).setCellValue("1");
row1.createCell((short)1).setCellValue("AAAA");
row1.createCell((short)2).setCellValue("90");
row1.createCell((short)3).setCellValue("A");

HSSFRow row2 = sheet1.createRow((short)2);
row2.createCell((short) 0).setCellValue("2");
row2.createCell((short) 1).setCellValue("BBBB");
row2.createCell((short) 2).setCellValue("70");
row2.createCell((short) 3).setCellValue("B");

HSSFRow rowhead1 = sheet2.createRow((short)0);
rowhead1.createCell((short) 0).setCellValue("Class");
rowhead1.createCell((short) 1).setCellValue("Age");
rowhead1.createCell((short) 2).setCellValue("Address");
rowhead1.createCell((short) 3).setCellValue("Phone Number");

HSSFRow row3 = sheet2.createRow((short)1);
row3.createCell((short)0).setCellValue("5");
row3.createCell((short)1).setCellValue("10");
row3.createCell((short)2).setCellValue("Rohini,Delhi");
row3.createCell((short)3).setCellValue("1111111111");

HSSFRow row4 = sheet2.createRow((short)2);
row4.createCell((short) 0).setCellValue("6");
row4.createCell((short) 1).setCellValue("11");
row4.createCell((short) 2).setCellValue("Vasant kunj,Delhi");
row4.createCell((short) 3).setCellValue("2222222222");
sheet1.setSelected(true);

sheet2.setSelected(false);

FileOutputStream fileOut = new FileOutputStream("c:\\selectingSheet.xls");
hwb.write(fileOut);
fileOut.close();
out.println("Your excel file has been generated");
} catch ( Exception ex ) {
System.out.println(ex);

}%>
<a href="readExcel.jsp">Read And Edit Excel File</a>

May 31, 2010 at 5:18 PM

continue..

2)readExcel.jsp

<%@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"%>
<form >
<%
short a=0;
short b=1;
short c=2;
short d=3;
int i=0;
String filename ="C:/selectingSheet.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;
%>
Sheet <%=j%><%
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 1; r < rows; r++){
HSSFRow row = sheet.getRow(r);
if (row != null) {
int cells = row.getPhysicalNumberOfCells(); %><br><%
HSSFCell cell1 = row.getCell(a);
if (cell1 != null){
String value = null;
switch (cell1.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA :
value = "FORMULA ";
break;
case HSSFCell.CELL_TYPE_NUMERIC :
value = ""+cell1.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING :
value = cell1.getStringCellValue();
break;
}
%>
<input type="text" name="roll" value="<%=value%>"><%
}
HSSFCell cell2 = row.getCell(b);
if (cell2 != null){
String value = null;
switch (cell2.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA :
value = "FORMULA ";
break;
case HSSFCell.CELL_TYPE_NUMERIC :
value = ""+cell2.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING :
value = cell2.getStringCellValue();
break;
}%>
<input type="text" name="name" value="<%=value%>">
<% }
HSSFCell cell3 = row.getCell(c);
if (cell3 != null){
String value = null;
switch (cell3.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA :
value = "FORMULA ";
break;
case HSSFCell.CELL_TYPE_NUMERIC :
value = ""+cell3.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING :
value = cell3.getStringCellValue();
break;
} %>
<input type="text" name="marks" value="<%=value%>">
<% }
HSSFCell cell4 = row.getCell(d);
if (cell4 != null){
String value = null;
switch (cell4.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA :
value = "FORMULA ";
break;
case HSSFCell.CELL_TYPE_NUMERIC :
value = ""+cell4.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING :
value = cell4.getStringCellValue();
break;
}
%> <input type="text" name="grade" value="<%=value%>">
<% } }%>
<input type="submit" value="Edit">
<% }%>
<br><br><br><br><%
i++;}}
catch (Exception ex){
} }
%> </form>

Thanks









Related Tutorials/Questions & Answers:
read excel data from jsp - JSP-Servlet
read excel data from jsp  Hi how to read excel file from jsp? Excel file is created manually entered data having many sheets? and read the entire...)excel.jsp: Read And Edit Excel File  continue
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
Advertisements
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 for scientific research analysis. My team members sends research data in excel file
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
Read code from excel sheet and upload into database using JSP
Read code from excel sheet and upload into database using JSP  I want to upload data to database from an excel worksheet using jsp ...Please help
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
Read data from Excel and insert in to DB and export data from DB to Excel
Read data from Excel and insert in to DB and export data from DB to Excel  Read data from Excel and insert in to DB and export data from DB to Excel Hi, I need to read the data from excel and I need to insert the same in to DB
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 read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page ... the data from this .properties file and display it in table format. Ex:by using... = DEDCHGG_PWDP and goes on... I have to create a jsp page to show these data
JSP/Servlet to read and update Excel
JSP/Servlet to read and update Excel  Hi Team, My requirement is based upon my input(name) value via one jsp, the program(jsp/servlet) should fetch all the column values which is related to my input(name) from Excel(.xls
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
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
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter...(); out.println("Data is saved in excel file."); }catch ( Exception ex ){ } %>
read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks
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
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
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
php import data from excel to mysql
php import data from excel to mysql  php import data from excel to mysql
Read a particular column in excel sheet - JSP-Servlet
Read a particular column in excel sheet  hi sir i used ur code,but where i have to put that index value ,i am calling the following methods... in jsp is " + Attachment.length); isValid
Function data from web in MS excel
Function data from web in MS excel  Hello, I would like to import data from one webpage to Excel using function Data - From Web. The problem is that this web page has at the end .jsp . When I open it via Excel, click to data
Read a particular column in excel sheet - JSP-Servlet
Read a particular column in excel sheet  hi sir i want to a read a excel sheet ,in that i have to take a particular column that contains a mailIds ,use that column to send a mail to all so how to do this sir give me some code
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
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 read excel data and store it in database - Java Beginners
How to read excel data and store it in database  Hi, I want a java code to read data from excel and store it in Ms Access database.I tried the code... read data into database.So please give me some sample code. Thanks
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...; String sSql = "SELECT DISTINCT FinancialYear FROM details ORDER BY FinancialYear
export data to excel sheet - JSP-Servlet
export data to excel sheet  Hi.. how to export data to excel sheet from jsp? and how to update the excel sheet from jsp? and how to get the data from excel sheet? and how to make calculations in excel sheet like total avg
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 application project in jsp. In webform ,I am displaying database data in html table. So my question is ,I want so save this html format data in pdf/excel format
Store data in HTML forms from Excel sheet
Store data in HTML forms from Excel sheet  I have a excel file having multiple coloums, and having one Html page having forms corrospoding to excel coloums. I want to auto fill up the excel data into html forms, Any one please
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... in the column of the excel and also the mechanism to get this data and display
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
how read excel data into database using struts2 with hibernate
how read excel data into database using struts2 with hibernate   hi friends, i am venkat i am started learning struts 2, please help me how to read excel data into database using struts2 with hibernate, please show me
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending... this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending... this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel
export data from database to excel sheet - JDBC
export data from database to excel sheet  I am facing a problem about exporting required data from database table to ms-excel sheet.i mean whenever I...("Data is saved in excel file."); rs.close(); connection.close(); } catch
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project... the data in excel file, i have to plot graphs based on CELL ID selected. please help... that reads an excel file using POI api and using the data of excel file
excel sheet reading and using that data - JSP-Servlet
excel sheet reading and using that data  i have to do a read a excel sheet file of a employee record and then i have to use a employee details to send mail to those employees how to do in jsp sir please help me sir.. Thanks
Export Extjs Gridview data to excel in jsp
Export Extjs Gridview data to excel in jsp  i need to export the extjs girdview data to excel can you please help me thanks in advance
getting the excel path throuh web browser given from client(i.e thruogh .jsp)
getting the excel path throuh web browser given from client(i.e thruogh .jsp)  1)when client uploads the excel sheet through a .jsp page, 2)get that excel path from web browser and read the data from the excel and printing
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
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
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
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
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending a code now i am getting a particular column value i.e EmailId column... to all the employees that are in the excel sheet.So in the previous code i have got
Java swing: Export excel sheet data to JTable
Java swing: Export excel sheet data to JTable In this tutorial, you will learn how to read data from excel file and export it to JTable. In swing... and POI-HSSF api. Here we are using JExcel api to fetch the data from excel sheet
JSP TO EXCEL
JSP TO EXCEL  Hi sir/mam, How to import data to excel using jsp without retrieving database.   friend, you can't import excel data into the middle of an HTML pages (your JSP will result in an HTML page
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
Error in reading Excel data using jsp
Error in reading Excel data using jsp  ERROR while executing bellow code:java.io.IOException: Invalid header signature; read 576460838270094160.... ---------- java.io.IOException: Invalid header signature; read 576460838270094160, expected
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

Ads