Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display Excel file in HTML

Posted on 2004-08-03
18
Medium Priority
?
11,246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 240 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 160 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

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.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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