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



Home Answers Viewqa JSP-Servlet read excel data from jsp
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raghavendra
read excel data from jsp
2 Answer(s)      4 years and 7 months 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?


Advertisement
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 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 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 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
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 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
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
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 ){ } %>
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 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
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
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
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
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
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
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
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
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
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
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
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
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
 

 

 

DMCA.com