• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11252
  • Last Modified:

Display Excel file in HTML

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
MaxTo
Asked:
MaxTo
  • 8
  • 7
  • 2
  • +1
2 Solutions
 
sajuksCommented:
Use this at the top of your page
<%
  Response.Buffer = TRUE
   Response.ContentType = "application/vnd.ms-excel"
%>
0
 
sajuksCommented:
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
 
sajuksCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
MaxToAuthor Commented:
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
 
sajuksCommented:
<%
   
 your excel file geneartion
%>
<script language=javascript>
window.href.location="yourfilenamehere.xls";

</script>
0
 
MaxToAuthor Commented:
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
 
MaxToAuthor Commented:
Dear sajuks,

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


Thanks
Max
0
 
sajuksCommented:
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
 
sajuksCommented:
or is your excel file already present on the server and you want to just display it ?
Some process flow would help
0
 
VincentPugliaCommented:
Hi MaxTo,

You might find this tutorial helpful:

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

Vinny
0
 
Neil ThompsonSenior Systems DeveloperCommented:
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
 
MaxToAuthor Commented:
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
 
MaxToAuthor Commented:
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
 
MaxToAuthor Commented:
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
 
sajuksCommented:
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
 
sajuksCommented:
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
 
MaxToAuthor Commented:
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
 
Neil ThompsonSenior Systems DeveloperCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now