Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML to EXCEL on the fly.

Status
Not open for further replies.

cakeday

Programmer
Nov 5, 2003
6
US
Hi all,

I have a webpage, which displays the records queried from the oracle database on the web using HTML table(s).

I want to give the users a button,which upon clicked should exports whatever is on the webpage to an excel spreadsheet.

I cannot hardcode and have a .xls file sitting on the server, because in my webpage the parameters are passed dynamically, so i need to create the excel file on the fly.

I want to accomplish this using javascript, because the web page technology i am using(PSP - PL/SQL server pages supports javascript)

So can anyone tell me, how to do this. Any sample codes or links will be very useful. Thank you in advance.

FYI, I am newbie when it comes to javascript.
 
cakeday,

The simplest way I found is this. Before you write your table, put this above it.

<%
Response.ContentType = &quot;application/vnd.ms-excel&quot;
%>

<table>
<tr>
<td>field1</td><td>field2</td><td>field3</td>
<td>field1</td><td>field2</td><td>field3</td>
</tr>
</table>



fengshui_1998
 
Hi,

Thank you, so much!

I tried doing what fengshui_1998 suggested.

So is it as simple as adding
ContentType = &quot;application/vnd.ms-excel&quot; before the HTML table?

I tried doing it, i am also going to copy and paste the code below.

Since i am using the oracle internet server i have to use the following,(where owa_util - A package, mime_header -A procedure within that package.. and so on and so forth)

<%
owa_util.mime_header(ccontent_type => 'application/vnd.ms-excel');
%>

My HTML code looks like as follows,
<!-- PL/SQL Language Definition Section -->
<%@ page language=&quot;PL/SQL&quot; %>

<!-- Begin web page coding -->

</HEAD>

<BODY>

<%
DECLARE
-- Declaring all variables for the procedure code
v_minage prov_professional.min_age%TYPE;
v_firstname prov_professional.first_name%TYPE;
v_city prov_professional.city%TYPE;
v_pcpid prov_professional.pcp_id%TYPE;


CURSOR c1 IS select min_age,first_name,city,pcp_id
from prov_professional;

BEGIN

owa_util.mime_header(ccontent_type => 'application/vnd.ms-excel');
%>

<table border=&quot;1&quot;>
<tr>
<th>Minimum Age</th>
<th>First Name</th>
<th>City</th>
<th>PCP ID</th>
</tr>

<%
OPEN c1;

LOOP

Fetch c1 into v_minage,v_firstname,v_city,v_pcpid;
exit when c1%NOTFOUND;
%>

<tr>
<td><%= v_minage %></td>
<td><%= v_firstname %></td>
<td><%= v_city %></td>
<td><%= v_pcpid %></td>
</tr>

<%
END LOOP;
%>

</table>

</CENTER>
</BODY>

<%
END;
%>

But when i run this code on the server, it still opens the data in an html table, but on the top line it says,
Content-type: application/vnd.ms-excel

Can anybody help me with this?

Thank you all in advance,
Kalpa.
 
The Content Type header must be the FIRST line you output form your program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top