Home Answers Viewqa JSP-Servlet read excel data from jsp

 
 


raghavendra
read excel data from jsp
2 Answer(s)      3 years ago
Posted in : JSP-Servlet

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 Pages:
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
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 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 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 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
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
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
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
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 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 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
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
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
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
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
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
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
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
Excel - JSP-Servlet
Excel  How to export data from jsp to excel sheet. I am using struts1.2 in my application.  Hi friend, Code to data from Jsp to excel...: "success.jsp" For more information on excel sheet Using JSP visit
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 ){ } %>
excel
excel  how to save excel sheet data into the database using poi api... ) { String fileName="test.xls"; Vector dataHolder=read(fileName); saveToDatabase(dataHolder); } public static Vector read(String fileName
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
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
To read a excel with chart - Java Beginners
To read a excel with chart   Hi, I need to read the data in an excel which is in chart format using java. when I directly change the extention of excel file to CSV i am not getting the data in the chart.Please help me
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
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
update excel sheet using jsp::
update excel sheet using jsp::   Hi Sir,... I have a excel... given excel sheet and display it into another excel sheet using jsp" i am using 'session' to get the empid from one page to another jsp
How to insert rows from Excel spreadsheet into database by browsing the excel file?
-Servlet/18638-Read-Excel-data-using-JSP-and-update-MySQL-databse.html...How to insert rows from Excel spreadsheet into database by browsing the excel file?  I want to insert rows from excel sheet to database.for this i
to read data stored in ArrayList - Struts
them from database. Now i want to read the data of all 4 User objects from jsp file using struts2 tag. i have done the following thing, but i am getting data...to read data stored in ArrayList  this is regarding struts2, i have
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
php import data from excel to mysql
php import data from excel to mysql  php import data from excel to mysql
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
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... the data from database, create an excel file and data insert into newly
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
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
create folders and sub folders based on excel data
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... Current form this excel sheet how can i read the data line
Read Excel(.xlsx) document using Apache POI
Read Excel(.xlsx) document using Apache POI In this section, you will learn how to read Excel file having .xlsx extension using Apache POI library. In the below example, we will read excel document having one sheet named as "new
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
excel report fro jsp mysql
excel report fro jsp mysql  Dear Sir, I am facing some problem while generating excel report form mysql database using jsp code. With the help from... data. But I need your help for generating a excel file from mysql DB for blob
How to upload a large excel file - JSP-Servlet
How to upload a large excel file   Dear sir , How to upload a large excel file and how to read a that large excel file or how to get a each column values from that large excel file.For small file i am getting values
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
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 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
How to read excel contents when uploaded
How to read excel contents when uploaded  I am working on a project where the user uploads his excel file. Jsp page must read the excel contents... files.Please do help..   user logins and he uploads his excel file. the excel
insert excel value in to oracle data base
the data from the excel file using JDBC. For this you need to create dsn...insert excel value in to oracle data base  Hi All I am using... Driver do Microsoft Excel driver. Click finish button 3)Add Data Source Name
Data read. - XML
Data read.  How to store or read data in XML from Struts.Plz give me example. Thanx
jsp to excel - JSP-Servlet
jsp to excel  Hi All, I'm writing a program of jsp to Excel conversion with Using POI. My problem is i'm unable to put multiple data into excel...)); } FileOutputStream fileOut = new FileOutputStream("c:\\excel\\wct.xls

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.