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

Problem Opening Excel Output from ASP

Status
Not open for further replies.

rvancleef

Programmer
Apr 8, 2003
34
US
I am trying to generate an online report where the user can select ASP or XL output. When the HTML Output is selected, the ASP executes without issue and is rendered. When the "XL" value is passed, this line of code inserts the response.ContentType statement that I was expecting would render Excel.

If strComp(request.querystring("output"),"XL")=0 Then
response.ContentType = "application/vnd.ms-excel"
End If

Currently what is happening is that I receive the Open/Save file Pop-Up. Then if I select "Open", I receive an error that IE "Could not Open file ' If I select "Save" file, then the error displays a message the the site could not be accessed. Both of these errors are also present if I do not pass a querystring.

Are there any settings on IIS required in order to enable the XL ContentType parameter to work? What am I doing wrong?
 
<% OPTION EXPLICIT
If strComp(request.querystring(&quot;output&quot;),&quot;XL&quot;)=0 Then
response.ContentType = &quot;application/vnd.ms-excel&quot;
End If%>
<!-- #include file=&quot;../lib/utils.asp&quot; -->
<%
'ProjInfo Query
DIM rsProj,spdProj
Set spdProj=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
spdProj.Add &quot;name1&quot;,&quot;@ProjID&quot;
spdProj.Add &quot;type1&quot;, adInteger
spdProj.Add &quot;value1&quot;,Session(&quot;ProjID&quot;)
SET rsProj = getRSFromProc(&quot;proc_GetProjInfo&quot;,1,spdProj)
'ProjectStaffQuery
%>
<HTML>
<HEAD>
<TITLE>Project Summary Report</TITLE>
<META http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;><LINK rel=&quot;StyleSheet&quot; href=&quot;../lib/itmanager.css&quot; type=&quot;text/css&quot;>
</HEAD>
<BODY>
<TABLE> <!--Begin Page Content-->
<TR>
<TD class=&quot;MajorTitle&quot;>
</TD>
</TR>
<TR>
<TD>
<TABLE>
<TR><TD width=&quot;250&quot; rowspan=&quot;4&quot;><IMG src=&quot;../images/gclogo.gif&quot; height=&quot;74&quot; width=&quot;115&quot;></TD><TD Class=&quot;MajorTitle&quot; width=&quot;450&quot;><BR>Project Summary Report</TD></TR>
<TR><TD Class=&quot;fd&quot; width=&quot;450&quot;>Project Name: <%= Session(&quot;ProjName&quot;) %></TD></TR>
<TR><TD Class=&quot;fd&quot; width=&quot;450&quot;>Project ID: <%= Session(&quot;ProjID&quot;) %></TD></TR>
<TR><TD Class=&quot;fd&quot; width=&quot;450&quot;>Sponsor: <%= getNameFromID(rsProj(&quot;Sponsor&quot;))%></TD></TR>
</TABLE><br>
</TD>
</TR>
<TR>
<TD class=&quot;MajorTitle&quot;>
</TD>
</TR>
<TR>
<TD class=&quot;MinorTitle&quot;> Project Info
<BR><IMG src=&quot;../images/inactivetab_top_edge.gif&quot; height=&quot;1&quot; width=&quot;700&quot;>
</TD>
</TR>
<TR>
<TD>
<TABLE>
<TR><TD Class=&quot;fh&quot; width=&quot;100&quot;>Status:</TD><TD Class=&quot;fd&quot; width=&quot;600&quot;><%= rsProj(&quot;Status&quot;) %></TD></TR>
<TR><TD Class=&quot;fh&quot; width=&quot;100&quot;>Priority:</TD><TD Class=&quot;fd&quot; width=&quot;600&quot;><%= rsProj(&quot;Priority&quot;)%></TD></TR>
<TR><TD Class=&quot;fh&quot; width=&quot;100&quot;>Scope Summary:</TD><TD Class=&quot;fd&quot; width=&quot;600&quot;><%= formatLDForHTML(rsProj(&quot;ScopeSummary&quot;))%></TD></TR>
<TR><TD Class=&quot;fh&quot; width=&quot;100&quot;>Project Review:</TD><TD Class=&quot;fd&quot; width=&quot;600&quot;><%= formatLDForHTML(rsProj(&quot;ProjRev&quot;))%><br></TD></TR>
</TABLE>
</TD>
</TR>
<TR>
<TD class=&quot;MinorTitle&quot;> Project Staff and Time
</TD>
</TR>
<TR>
<TD><IMG src=&quot;../images/inactivetab_top_edge.gif&quot; height=&quot;1&quot; width=&quot;700&quot;>
</TD>
</TR>
<TR>
<TD>
<TABLE cellspacing=&quot;0&quot; cellpadding=&quot;1&quot;>
<%DIM rsProjStaff,spdProjStaff
'Get values from the Assignment
Set spdProjStaff=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
spdProjStaff.Add &quot;name1&quot;,&quot;@ProjID&quot;
spdProjStaff.Add &quot;type1&quot;, adInteger
spdProjStaff.Add &quot;value1&quot;,Session(&quot;ProjID&quot;)
SET rsProjStaff = getRSFromProc(&quot;proc_GetProjStaff&quot;,1,spdProjStaff)
If rsProjStaff.EOF Then
%><tr><td CLASS=&quot;feedback&quot;>There are currently no resources assigned to this project</td></tr><%
ELSE%>
<tr><td>Staff</td><td>Estimated Hours</td><td>Actual Hours</td><td>Variance</td><td>Overtime</td></tr>
<%
DO UNTIL rsProjStaff.EOF
IF I MOD 2 = 0 Then
vcolor=&quot;#FFFFFF&quot;
Else
vcolor=&quot;#CCCCFF&quot;
End If
%>
<TR bgcolor=&quot;<%= vcolor%>&quot;>
<TD class=&quot;ld&quot; width=200><%= rsProjStaff(&quot;FName&quot;)%> <%= rsProjStaff(&quot;Lname&quot;)%></TD>
<TD class=&quot;ld&quot; width=100><%= rsProjStaff(&quot;EstHours&quot;)%></TD>
<TD class=&quot;ld&quot; width=100><%= rsProjStaff(&quot;tHours&quot;)%></TD>
<%If CInt(rsProjStaff(&quot;EstHours&quot;))-rsProjStaff(&quot;tHours&quot;)> 0 Then%>
<TD class=&quot;ld&quot; width=100><%= rsProjStaff(&quot;EstHours&quot;)-rsProjStaff(&quot;tHours&quot;)%></TD>
<%Else%>
<TD class=&quot;err&quot; width=100><%= rsProjStaff(&quot;EstHours&quot;)-rsProjStaff(&quot;tHours&quot;)%></TD>
<%End If%>
<TD class=&quot;ld&quot; width=100><%= rsProjStaff(&quot;Overtime&quot;)%></TD>
</TR><%
I=i+1
rsProjStaff.MoveNext
Loop
End If
%>
</TABLE>
</TD>
</TR>
<TR>
<TD class=&quot;MinorTitle&quot;> Project Milestones
</TD>
</TR>
<TR>
<TD><IMG src=&quot;../images/inactivetab_top_edge.gif&quot; height=&quot;1&quot; width=&quot;700&quot;>
</TD>
</TR>
<TR>
<TD>
<TABLE cellspacing=&quot;0&quot; cellpadding=&quot;1&quot;>
<%'Get values from the Assignment
DIM rsMilestones,spdMilestones
Set spdMilestones=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
spdMilestones.Add &quot;name1&quot;,&quot;@ProjID&quot;
spdMilestones.Add &quot;type1&quot;, adInteger
spdMilestones.Add &quot;value1&quot;,Session(&quot;ProjID&quot;)
SET rsMilestones = getRSFromProc(&quot;proc_GetProjMilestones&quot;,1,spdMilestones)
If rsMilestones.EOF Then
%><tr><td class=&quot;feedback&quot;>There are currently no Milestones associated with this project.</td></tr><%
ELSE%>
<tr><td>Milestone</td><td>Estimated Date</td><td>Actual Date</td><td>Variance</td></tr>
<%
DO UNTIL rsMilestones.eof
IF I MOD 2 = 0 Then
vcolor=&quot;#FFFFFF&quot;
Else
vcolor=&quot;#CCCCFF&quot;
End If
%>
<TR bgcolor=&quot;<%= vcolor%>&quot;>
<TD class=&quot;ld&quot; width=100>
<% 'Display the Custom Milestone Name if Other, Otherwise display the default Milestone Name in the iFrame List
If strComp(rsMilestones(&quot;MilestoneName&quot;),&quot;Other&quot;)=0 Then
response.Write rsMilestones(&quot;OtherDesc&quot;)
Else
response.Write rsMilestones(&quot;MilestoneName&quot;)
End If%></TD>
<TD class=&quot;ld&quot; width=100><%= rsMilestones(&quot;ProjectedDate&quot;)%></TD>
<TD class=&quot;ld&quot; width=100><%= rsMilestones(&quot;ActualDate&quot;)%></TD>
<TD class=&quot;ld&quot; width=100><%= rsMilestones(&quot;ProjectedDate&quot;)-rsMilestones(&quot;ActualDate&quot;)%></TD>
</TR><%
I=i+1
rsMilestones.MoveNext
Loop
End If
%>
</TABLE>
</TD>
</TR>
<TR>
<TD class=&quot;MinorTitle&quot;> Project Notes
</TD>
</TR>
<TR>
<TD><IMG src=&quot;../images/inactivetab_top_edge.gif&quot; height=&quot;1&quot; width=&quot;700&quot;>
</TD>
</TR>
<TR>
<TD>
<TABLE cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; Width=683><%
'Get values from the Assignment
DIM rsNotes,I, VCOLOR, spdNotes
Set spdNotes=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
spdNotes.Add &quot;name1&quot;,&quot;@ProjID&quot;
spdNotes.Add &quot;type1&quot;, adInteger
spdNotes.Add &quot;value1&quot;,Session(&quot;ProjID&quot;)
SET rsNotes = getRSFromProc(&quot;proc_GetProjNotes&quot;,1,spdNotes)
If rsNotes.EOF Then
%><tr><td class=&quot;feedback&quot;>There are currently no notes associated with this project.</td></tr><%
ELSE
DO UNTIL rsNotes.eof
IF I MOD 2 = 0 Then
vcolor=&quot;#FFFFFF&quot;
Else
vcolor=&quot;#CCCCFF&quot;
End If
%>
<TR bgcolor=&quot;<%= vcolor%>&quot;>
<TD class=&quot;ld&quot; width=150><%= rsNotes(&quot;tmstamp&quot;)%></TD>
<TD class=&quot;ld&quot; width=350><%= rsNotes(&quot;subject&quot;)%></TD>
<TD class=&quot;ld&quot; width=100><%= rsNotes(&quot;fname&quot;)%> <%= rsNotes(&quot;lname&quot;)%></TD>
</TR>
<TR bgcolor=&quot;<%= vcolor%>&quot;>
<TD class=&quot;ld&quot; colspan=&quot;3&quot;><%= rsNotes(&quot;Note&quot;)%></TD>
</TR><%
I=i+1
rsNotes.MoveNext
Loop
End If
%>
</TABLE><br>
</TD>
</TR>
<TR>
<TD><IMG src=&quot;../images/inactivetab_top_edge.gif&quot; height=&quot;1&quot; width=&quot;700&quot;>
</TD>
</TR>
<TR>
<TD class=&quot;fd&quot;> Please contact Project Manager <%= rsProj(&quot;fname&quot;) %> <%= rsProj(&quot;lname&quot;) %> for any questions/concerns related to this report.
</TD>
</TR> <!--End Page Content-->
</TABLE>
</BODY>
</HTML>
<% ENSURECONNCLOSED() %>
 
the big issue i see in this code is that you're outputting HTML content to an XL based content header, XLS output needs to be in standard CSV formatting with vbCrLf's for each new line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top