File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Export to excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Export to excel" Watch "Export to excel" New topic

Export to excel

prabhu kandanur
Ranch Hand

Joined: Oct 18, 2003
Posts: 34
source code required to .. "export to excel "
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Look for the apache POI project.
Faz Rashad

Joined: Nov 18, 2004
Posts: 6
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:

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

String query = "Select * from Customers";

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


/*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"/>

<TITLE>Export Data to Excel</TITLE>

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

//Display results in excel

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


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




Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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
I agree. Here's the link:
subject: Export to excel
It's not a secret anymore!