• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Export to excel

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
source code required to .. "export to excel "
prabhu
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look for the apache POI project.
D.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Java, so my solution might not be very sofisticated. But it works.

//Here is the code I used:
//This is an HTML or JSP page, that is used to pass the query to a seocnd page:

<html>
<head><title>Pass SQL Query </title></head>
<body>

<%
String query = "Select * from Customers";
%>

<p><font size="+1">[<a href="excel.jsp?SQL=<%=query%>">Export results to Excel</a>]</font>

</body>
</html>

-------------------------------------------------------
/*Second JSP Page will look something like this:
*Notice that I used a Bean here "JDBC_Wrapper" to open the database *connection and execute the query.
*/

<%@ page import = "java.sql.*, somefolder.JDBC_Wrapper" %>
<jsp:useBean id="myCBean" class="somefolder.JDBC_Wrapper" scope="session"/>

<HTML>
<HEAD>
<TITLE>Export Data to Excel</TITLE>
</HEAD>
<body>

<%
String SQL = request.getParameter("SQL");
myCBean.DbInit();
ResultSet rs = myCBean.queryTable(SQL);

//Display results in excel
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition","attachment;filename=report.xls");
%>

<table border="1" >
<thead>
<tr>
<th>Column1 Name</th>
<th>Column2 Name </th>
</tr>
</thead>

<tbody>

<%while (rs.next()){ %>
<tr>
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
</tr>
<% } %>

</tbody>
</table>

<%

myCBean.DbClose();
%>

</body>
</html>
 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use csv!!! that is comma separator value.

String x="bla, bla";

when you write it in csv the result will be "bla bla" in 2 separtes boxes.

best of luck
 
reply
    Bookmark Topic Watch Topic
  • New Topic