middletree wrote:
I did a search in this forum, as well as at www.asp.faq.com, and
MSDN, and would like to know how to use ASP to build a report and create an
..xls file as a result.
Here's an ASP that I wrote that will help you. Basically, create your
report in HTML, then place a server.execute( "makeexcel.asp" ) (or
whatever you call this program), just before your HTML in the report
file. What makes this good is that you can fine tune your report in
HTML, then add the server.execute and it will convert it to XLS.
Couple of notes: You set session("tablen ame") to whatever XLS filename
you want. There are also a number of settings you use, anything that
calls the DEF function is a session var you can set before executing
this file. In addition, session("rowsto repeat") is a value for the
number of rows in your HTML to repeat at the top of each page.
There are also various styles that I've created that you can use...
<%
response.Buffer = true
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der "Content-Disposition","f ilename=" &
session("tablen ame") &".xls"
function def(val)
if session(val)<>" " then
execute(val &"=" & session(val))
session(val)=""
end if
end function
'-------------default settings-----------------------------------
fitheight=9999
fitwidth=1
orientation="la ndscape"
lmargin=.25
rmargin=.25
tmargin=.25
bmargin=.75
'
def "fitheight"
def "fitwidth"
def "orientatio n"
def "lmargin"
def "rmargin"
def "tmargin"
def "bmargin"
%>
<html xmlns:v="urn:sc hemas-microsoft-com:vml"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns="http://www.w3.org/TR/REC-html40">
<style>
@page
{margin:<%=lmar gin%>in <%=rmargin%>i n <%=bmargin%>i n <%=tmargin%>i n;
mso-footer-data:"&LPrinted on &D &T&RPage &P of &N";
mso-header-margin:.25in;
mso-footer-margin:.25in;
mso-page-orientation:<%= orientation%>;
mso-horizontal-page-align:center;}
td {font-size:10px;white-space:normal;}
br {mso-data-placement:same-cell;}
..currency { mso-number-format:"_($* #,##0.00_)"}
..currencybold {mso-number-format:"_($* #,##0.00_)";fon t-weight:700;}
..number2dec {mso-number-format: Fixed;}
..number2decbol d {mso-number-format: Fixed; font-weight:700;}
..text {mso-number-format:General; text-align:general;w hite-space:
normal }
..num2text {mso-style-parent:text; mso-number-format:"\@";whi te-space:
normal}
</style>
<xml>
<x:ExcelWorkboo k>
<x:ExcelWorkshe ets>
<x:ExcelWorkshe et>
<x:Name>Sheet 1</x:Name>
<x:WorksheetOpt ions>
<x:DoNotDisplay Gridlines/>
<x:CodeName>She et1</x:CodeName>
<x:FitToPage/>
<x:Print>
<x:ValidPrinter Info/>
<x:Scale>10</x:Scale>
<x:FitHeight><% =fitheight%></x:FitHeight>
<x:FitWidth><%= fitwidth%></x:FitWidth>
<x:HorizontalRe solution>600</x:HorizontalRes olution>
<x:VerticalReso lution>600</x:VerticalResol ution>
</x:Print>
</x:WorksheetOpti ons>
<x:AutoFormatWi dth/>
</x:ExcelWorkshee t>
<x:AutoFormatWi dth/>
</x:ExcelWorkshee ts>
</x:ExcelWorkbook >
<%if session("rowsto repeat")>0 then%>
<x:ExcelName>
<x:Name>Print_T itles</x:Name>
<x:SheetIndex>1 </x:SheetIndex>
<x:Formula>=She et1!$1:$<%=sess ion("rowstorepe at")%></x:Formula>
</x:ExcelName>
<%end if%>
</xml>