Solved

Display Excel file in HTML

Posted on 2004-08-03
18
11,232 Views
Last Modified: 2012-05-05
Dear ALL Experts,

   How I can display the excel file in web browser?
What i means is now i upload the .xls into my server, then got a page will display the content information from the .xls file. SO now how i can create the page to display the .xls file from the website?

I know that need to setup the contentType, but i don't know how to show out.

can anybody write me the simple complete code?

Thanks

Max
0
Comment
Question by:MaxTo
  • 8
  • 7
  • 2
  • +1
18 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 11702602
Use this at the top of your page
<%
  Response.Buffer = TRUE
   Response.ContentType = "application/vnd.ms-excel"
%>
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11702609
Ex:1 http://support.microsoft.com/default.aspx?scid=kb;EN-US;199841
<%@ Language=VBScript %>
<%
   'Change HTML header to specify Excel's MIME content type
   Response.Buffer = TRUE
   Response.ContentType = "application/vnd.ms-excel"
%>
<HTML>
<BODY>
Here is the info you requested.<p>
<%
   ' Create ADO Connection object
   dim myConnection
   set myConnection = CreateObject("ADODB.Connection")
   
   ' Open SQL Server Pubs database...
   ' myConnection.Open "DSN=pubs;UID=sa"
   
   ' Get a recordset of info from Authors table...
   sqlStr = "SELECT au_fname,au_lname,phone FROM authors"
   set rsAuthors =  myConnection.Execute(sqlStr)
%>

<!-- Our table which will be translated into an Excel spreadsheet -->
<TABLE WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR>
   <TD><font size=+2>First Name</font></TD>
   <TD><font size=+2>Last Name</font></TD>
   <TD><font size=+2>Phone</font></TD>
</TR>
<!-- server-side loop adding Table entries -->
<% do while not rsAuthors.EOF %>
<TR>
   <TD><%=rsAuthors("au_fname")%></TD>
   <TD><%=rsAuthors("au_lname")%></TD>
   <TD><%=rsAuthors("phone")%></TD>
</TR>
<% rsAuthors.MoveNext
   loop
   ' Clean up
   rsAuthors.Close
   set rsAuthors = Nothing
   myConnection.Close
   set myConnection = Nothing
%>
</TABLE>
</BODY>
</HTML>
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11702611
ex:2
<%@LANGUAGE="VBSCRIPT"%>
<%
' Tells the browser to open table using MS-Excel
Response.ContentType = "application/vnd.ms-excel"
%>

<html>
<head>
<title>Excel MIME Type Example</title>


</head>
<body>
<!-- Sample Table with Data -->
<table border="0" cellspacing="1" cellpadding="1">
<tr bgcolor="#999999">
<td><b>Remote Address</b></td>
<td><b>HTTP User Agent</b></td>
<td><b>Date</b></td>
<td><b>Server Software</b></td>
</tr>
<tr>
<td>
<% =Request.ServerVariables("REMOTE_ADDR") %>
</td>
<td>
<% =Request.ServerVariables("HTTP_USER_AGENT") %>
</td>
<td>
<% = Date() %>
</td>
<td>
<% =Request.ServerVariables("SERVER_SOFTWARE") %>
</td>
</tr>
</table>
</body>
</html>
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:MaxTo
ID: 11702923
Dear sajuks,

Thanks for your help.
But from both of your example, how i pass the file in that and ask it to load out?
Example: now i want display the file name book1.xls.

actually what i want is something like this website http://www.cycom.com.my/download/newpricelist/newpricelist.html

It was using the xml. but i don't know how to do it like that in dynamic file to open.

Thanks

max
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11703074
<%
   
 your excel file geneartion
%>
<script language=javascript>
window.href.location="yourfilenamehere.xls";

</script>
0
 

Author Comment

by:MaxTo
ID: 11703138
Dear sajuks,

the code you paste
<%
   
 your excel file geneartion
%>
<script language=javascript>
window.href.location="yourfilenamehere.xls";

</script>

what do your means by " your excel file geneartion"
is it you means the kind of look is the excel automatic genera out?

so for the full code is it write like this
<html>
<body>
<script language=javascript>
window.href.location="yourfilenamehere.xls";

</script>
</body>
</html>

still need to used or set
<%
  Response.Buffer = TRUE
   Response.ContentType = "application/vnd.ms-excel"
%>

at the top or not?

Max
0
 

Author Comment

by:MaxTo
ID: 11703165
Dear sajuks,

sorry.. can u write out the full code, because i am new hand in this program.


Thanks
Max
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11703276
The steps that you are trying to achieve is:
1. Upload a excel file
2. Create a link/button to display the excel file .
is that right ?
So have you got the upload file script ready ?
It would be easier to add this into the code that you already have.
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11703396
or is your excel file already present on the server and you want to just display it ?
Some process flow would help
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11704071
Hi MaxTo,

You might find this tutorial helpful:

http://www.asp101.com/samples/xl_data.asp

Vinny
0
 
LVL 3

Expert Comment

by:Neil Thompson
ID: 11705380
Hi

Take a look at this code, it's what i got my xls working superbly on last week

Neil

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21065956.html
0
 

Author Comment

by:MaxTo
ID: 11712654
To sajuks,

You really provide me a clear define step... now i don't have the upload file script ready. so i will create one, and is the upload image script and upload xls file script is the same?

If let said the excel file is already present in the server, how i can display it fro server?
what the different with those two?

DO you have the sample for those two? if got can you send to me at this email : tomax212@tm.net.my

sajuks, u really help me. i had try the sample code u give to me at the previous comments, but it wasn't what i want.

Thanks

Max
0
 

Author Comment

by:MaxTo
ID: 11712684
To  VincentPuglia,

From the site you give, is read the data from excel file, but will it look like this website show the data
http://www.cycom.com.my/download/newpricelist/newpricelist.html

what i want is same with this, and if got image inside excel file, the site you provide does it work?

Thanks

Max
0
 

Author Comment

by:MaxTo
ID: 11722804
Dear All Experts,

Can anyone help me to solve this problem, i'm urgen to solve this.
Does anyone have the sample code, please write me and complete code.

Thanks

Max
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11722937
MaxTo ,
 If you could clear some doubts,
1. The data that you want displayed in the excel format, is it data that is static, for eg, a excel file located on your server or is it some data that is being read from a database and then you need to display it in excel format.
2. Is the excel file located at the clients machine ?


To get the same fee land look as in the site that you provided wont be possible using just asp, what asp can do for you is opne the page in excel format.
0
 
LVL 33

Accepted Solution

by:
sajuks earned 60 total points
ID: 11723344
Check this link,
http://www.tutorialized.com/tutorials/ASP/Excel-and-ASP/1
It shows excel and asp examples
One of the examples asks for user input and then displays in excel format
http://www.codeave.com/asp/code.asp?u_log=148
0
 

Author Comment

by:MaxTo
ID: 11733112
Dear sajuks,

From the information and link you provide, now i still reading it, i will give an response on next week.
Thanks....

Max
0
 
LVL 3

Assisted Solution

by:Neil Thompson
Neil Thompson earned 40 total points
ID: 11733334
1) This will give you desired result.. You need to add your connection string/dsn and the tablename
2) To make the table name you need to do the following in Excel :
- highlight the rows and columns you want to show
- go to INSERT, NAME, DEFINE and add a name here (this will be your table name)
3) Set these 2 things below and this should work perfectly.

Neil

=======================================================
<%
dsmName = ' YOUR DSN HERE
myTable = ' YOUR TABLE NAME HERE

Set con = Server.CreateObject("ADODb.Connection")
Set rs = Server.CreateObject("ADODb.RecordSet")
con.open dsnName
Set rs = Server.CreateObject("ADODb.RecordSet")

sql = "select * from myTable"
rs.open sql,con

response.write "<table border=1>"
Do while not rs.EOF
      response.write "<tr>"      
     For Each f In rs.Fields
             response.write "<td>"
         If f.value & "" <> "" Then
               response.write f.value
         Else
               response.write "&nbsp;"
         End if
             response.write "</td>"
    Next                     
      rs.MoveNext
      response.write "</tr>"
Loop
response.write "</table>"
%>
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question