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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Contenttype = Excel problems 1

Status
Not open for further replies.

jcale4

Programmer
Aug 31, 2004
63
0
0
US
I'm having problems with a report opening in Excel from ASP. The report starts to pull, but then the excel window closes immediately.. here's the code:

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #include file="dbopen.inc" -->
<!-- #include file="ADOVBS.inc" -->
<%

ops = trim(request("ops"))

dim arrOPS
arrOPS = split(ops,",")

excelSQL = "SELECT " & arrOPS(1)
%>

<link rel="stylesheet" type="text/css" href="jstyle.css" />



<%'Response.ContentType = "application/vnd.ms-excel"%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  <td><font class="ti">Causecode</font></td>
<% for x = 2 to Ubound(arrOPS) %>
  <% if arrOPS(x) = "ccdescription" then %>
  <% excelSQL = excelSQL & ", ccdescription" %>
    <td><font class="ti">Cause Code Description</font></td>
  <% end if %>
  <% if arrOPS(x) = "acctnum" then %>
  <% excelSQL = excelSQL & ", acctnum" %>
    <td><font class="ti">Account Number</font></td>
  <% end if %>
  <% if arrOPS(x) = "acctname" then %>
  <% excelSQL = excelSQL & ", acctname" %>
    <td><font class="ti">Account Name</font></td>
  <% end if %>
  <% if arrOPS(x) = "entrydate" then %>
  <% excelSQL = excelSQL & ", entrydate" %>
    <td><font class="ti">Entry Date</font></td>
  <% end if %>
  <% if arrOPS(x) = "entrytime" then %>
  <% excelSQL = excelSQL & ", entrytime" %>
    <td><font class="ti">Entry Time</font></td>
  <% end if %>
  <% if arrOPS(x) = "contactname" then %>
  <% excelSQL = excelSQL & ", contactname" %>
    <td><font class="ti">Contact Name</font></td>
  <% end if %>
  <% if arrOPS(x) = "contactphone" then %>
  <% excelSQL = excelSQL & ", contactphone" %>
    <td><font class="ti">Contact Phone</font></td>
  <% end if %>
  <% if arrOPS(x) = "severity" then %>
  <% excelSQL = excelSQL & ", severity" %>
    <td><font class="ti">Severity Level</font></td>
  <% end if %>
  <% if arrOPS(x) = "product" then %>
  <% excelSQL = excelSQL & ", product" %>
    <td><font class="ti">Product Type</font></td>
  <% end if %>
  <% if arrOPS(x) = "opid" then %>
  <% excelSQL = excelSQL & ", opid" %>
    <td><font class="ti">Operator ID</font></td>
  <% end if %>
  <% if arrOPS(x) = "comments" then %>
  <% excelSQL = excelSQL & ", comments" %>
    <td><font class="ti">Comments</font></td>
  <% end if %>
  <% if arrOPS(x) = "iic" then %>
  <% excelSQL = excelSQL & ", iic" %>
    <td><font class="ti">IIC</font></td>
  <% end if %>
  <% if arrOPS(x) = "iicdescription" then %>
  <% excelSQL = excelSQL & ", iicdescription" %>
    <td><font class="ti">IIC Description</font></td>
  <% end if %>
<% next %>
  </tr>
</table>

<%
excelSQL = excelSQL & " FROM tblri21 " & session("whereSQLfinal")


set objRS = rtl.execute(excelSQL)
response.Write(objRS("causecode"))
%>
<table>
<% if not objRS.eof then %>
<% while not objRS.eof %>
<tr>
<% for g = 1 to ubound(arrOPS) %>
	<td><%=objRS(arrOPS(g))%></td>
<% next %>
</tr>
<% objRS.movenext %>
<% wend %>
<% end if %>
</table>
<% objRS.close %>
<% set objRS = nothing %>

<!-- #include file="dbclose.inc" -->
 
This is what I use to throw into the top of my database generated excel docs.

Top of the file, before I even include anything I have:

Code:
<%
Response.ContentType = "application/vnd.ms-excel" 
Response.AddHeader "content-disposition", "inline; filename=yourfilenamehere.xls"
%>

See if that slight modification helps you out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top