How to export grid into excel

Ads
 

How to export grid into excel

Hi, i created a grid panel i have to export it to the excel. please help me by some sample code. thanks in advance. cool day dude.

View Answers

October 3, 2012 at 4:38 PM

Here is a jsp application that retrieves database records in a table and export the data to excel file. You need POI api to run the given code.

1)data.jsp:

<%@page import="java.sql.*"%>
<form method="post" action="excelFile.jsp">
<table border=1>
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from employee");
while(rs.next()){
    %>
<tr><td><input type="text" name="name" value="<%=rs.getString("name")%>"></td><td><input type="text" name="address" value="<%=rs.getString("address")%>"></td><td><input type="text" name="contact" value="<%=rs.getString("contactNo")%>"></td><td><input type="text" name="email" value="<%=rs.getString("contactNo")%>"></td></tr>
<%
}
%>
</table>
<input type="submit" value="Export To Excel">
</form>

2)excelFile.jsp:

<%@page import="  java.io.*"%>  
<%@page import="  org.apache.poi.hssf.usermodel.*"%>  
<%
String name[]=request.getParameterValues("name");
String address[]=request.getParameterValues("address");
String contact[]=request.getParameterValues("contact");
String email[]=request.getParameterValues("email");

try{
String filename="c:/data.xls" ;
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet =  hwb.createSheet("sheet");

HSSFRow rowhead=   sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Name");
rowhead.createCell((short) 1).setCellValue("Address");
rowhead.createCell((short) 2).setCellValue("Contact No");
rowhead.createCell((short) 3).setCellValue("E-mail");
for(int i=0;i<name.length;i++){
    int j=i+1;
HSSFRow row=   sheet.createRow((short)j);
row.createCell((short) 0).setCellValue(name[i]);
row.createCell((short) 1).setCellValue(address[i]);
row.createCell((short) 2).setCellValue(contact[i]);
row.createCell((short) 3).setCellValue(email[i]);
}
FileOutputStream fileOut =  new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
out.println("Your excel file has been generated!");
} catch( Exception ex ) {
    System.out.println(ex);
}
%>

October 3, 2012 at 5:59 PM

hi thanks dude. here you created a table and exported to excel. but i created grid in extjs and have to export to the excel. please help me for that.. thanks dude.

Ads









Related Tutorials/Questions & Answers:
How to export grid into excel
How to export grid into excel  Hi, i created a grid panel i have to export it to the excel. please help me by some sample code. thanks in advance. cool day dude
How to export chart(graph) generated by jsp into a excel?
How to export chart(graph) generated by jsp into a excel?  How to export chart(graph) generated by jsp into a excel? I have a jsp page which generates charts . Now I need those charts to be exported into an excel.please help
Advertisements
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
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 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 add save as dialoguebox to export into excel instead of directly saving..
How to add save as dialoguebox to export into excel instead of directly saving..  Hello Sir, i followed ur tutorial to export into excel from database and generated excel file at particular directory of my system
How to export web page to excel using java or jsp or servlets
How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am... have a save as excel button, when I click this button I need these displayed
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
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
ModuleNotFoundError: No module named 'excel-export'
'excel-export' How to remove the ModuleNotFoundError: No module named 'excel-export' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'excel-export'  Hi, My Python
ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export'
: ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export'...ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export
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... be exported in to the excel file. any views??? Thanks in advance
Version of com.hynnet>dhtmlx-grid-excel dependency
List of Version of com.hynnet>dhtmlx-grid-excel dependency
Java Count word occurrence and export it to excel file
Java Count word occurrence and export it to excel file Here is an example... and display the result the result into excel file in the table form. Example...;Your excel file has been generated!"); } catch(Exception e
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 applications, sometimes, it is required to display the excel file data into the jtable
Export data to Excel Sheet in STRUTS 1.3
Export data to Excel Sheet in STRUTS 1.3  hi. how can i export content present on the jsp to excel sheet on button click..... and challenging part is i have to merge few rows and columns for a particular field(Value
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
Maven Dependency dhtmlx-grid-excel >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of com.hynnet >> dhtmlx-grid-excel version1.0.1 in your project
Maven Dependency dhtmlx-grid-excel >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.hynnet >> dhtmlx-grid-excel version1.0.0 in your project
ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export-demo'
: ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export-demo' How...ModuleNotFoundError: No module named 'odoo12-addon-excel-import-export-demo...-export-demo python with following command: pip install odoo12-addon-excel
export
export  how to export tabled data in jsp into excel
How to Unlock Excel Password
How to Unlock Excel Password  anyone help me how to recover lost Excel file password
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
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 execute a query then result will be display in MS-EXCEL sheet. please give me
how to use Excel Templet to write excel file using java.
how to use Excel Templet to write excel file using java.  how to use Excel Templet to write excel file using java
how make excel
how make excel  how make excel spreadsheet IN JAVA. please send this code argently   Hello Friend, Try the following code: import...(filename); hwb.write(fileOut); fileOut.close(); System.out.println("Your excel file
how to use Excel Template to write excel file using java
how to use Excel Template to write excel file using java  How to use Excel template to write data in that file using java
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 will be displayed in excel sheet.can you people please help me how to create

Ads