Solved

Display Excel file in HTML

Posted on 2004-08-03
18
11,224 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
Comment Utility
Use this at the top of your page
<%
  Response.Buffer = TRUE
   Response.ContentType = "application/vnd.ms-excel"
%>
0
 
LVL 33

Expert Comment

by:sajuks
Comment Utility
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
Comment Utility
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
 

Author Comment

by:MaxTo
Comment Utility
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
Comment Utility
<%
   
 your excel file geneartion
%>
<script language=javascript>
window.href.location="yourfilenamehere.xls";

</script>
0
 

Author Comment

by:MaxTo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
or is your excel file already present on the server and you want to just display it ?
Some process flow would help
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Expert Comment

by:VincentPuglia
Comment Utility
Hi MaxTo,

You might find this tutorial helpful:

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

Vinny
0
 
LVL 3

Expert Comment

by:NeilT
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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:NeilT
NeilT earned 40 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now