fritz_the_blank
asked on
ASP Export to Excel with multiple pages
Hello and thank you for reading this question.
I am exporting data from a database to an Excel spreadsheet via ADO in ASP using the following method:
<%response.ContentType="ap plication/ vnd.ms-exc el"%>
I simply iterate through my recordset placing the results in a table, and all works fine.
What I would like to be able to do, however, is to create a new sheet (or tab if you prefer) for each record, but I am not sure that it is possible to do so with ASP classic (although there is a solution with XML and ADO.net).
Does anybody have an idea how to do this in ASP classic?
I would appreciate any help,
Fritz the Blank
I am exporting data from a database to an Excel spreadsheet via ADO in ASP using the following method:
<%response.ContentType="ap
I simply iterate through my recordset placing the results in a table, and all works fine.
What I would like to be able to do, however, is to create a new sheet (or tab if you prefer) for each record, but I am not sure that it is possible to do so with ASP classic (although there is a solution with XML and ADO.net).
Does anybody have an idea how to do this in ASP classic?
I would appreciate any help,
Fritz the Blank
Patrick,
I remember I helped someone with this. Youc ant do it with contrent type, but generate excel on server side
See here
https://www.experts-exchange.com/questions/20727830/ASP-to-EXCEL-multiple-worksheets-and-worksheet-names.html?query=multiple+excel+sheets&searchType=topic
I remember I helped someone with this. Youc ant do it with contrent type, but generate excel on server side
See here
https://www.experts-exchange.com/questions/20727830/ASP-to-EXCEL-multiple-worksheets-and-worksheet-names.html?query=multiple+excel+sheets&searchType=topic
Copying the XML from the question mentioned above:
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sample Workbook</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sample Workbook 2</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
then creating multiple pages is a matter of adding a <x:ExcelWorksheet></x:Exce lWorksheet > node for each extra page.
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sample Workbook</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sample Workbook 2</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
then creating multiple pages is a matter of adding a <x:ExcelWorksheet></x:Exce
ASKER
I could use a little hand holding; how would I modify the following?
<%Response.Buffer = true%>
<%
dim strDataPath, strConnectString
dim objConnection, objRS
'set connection strings for entire application
strDataPath = server.MapPath("SomeDataba se.mdb")
strConnectString = "Provider=Microsoft.Jet.OL EDB.4.0;Us er ID=Admin;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;User Id=admin;PASSWORD=;"
if not IsObject("ojbConnection") then
set objConnection=Server.Creat eObject("A DODB.Conne ction")
objConnection.ConnectionTi meout = 15
objConnection.CommandTimeo ut = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
set objRS = Server.CreateObject("ADODB .Recordset ")
objRS.Open "SELECT fld1, fld2,fld3 FROM tblSomeTable", objConnection,3,3
%>
<html>
<body>
<%Response.Clear%>
<%response.ContentType="ap plication/ vnd.ms-exc el"%>
<%
Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
Response.Write("<TR>")
do while not objRS.EOF
Response.Write("<TR>")
Response.Write("<TD>" & objRS("fld1")& "</TD>")
Response.Write("<TD>" & objRS("fld3")& "</TD>")
Response.Write("<TD>" & objRS("fld1")& "</TD>")
Response.Write("</TR>")
objRS.MoveNext
loop
%>
</Table>
</body>
</html>
<%
if objRS.State <> 0 then
objRS.Close
end if
set objRS = Nothing
if objConnection.state <> 0 then
objConnection.Close
end if
set objConnection = Nothing
Response.End
%>
<%Response.Buffer = true%>
<%
dim strDataPath, strConnectString
dim objConnection, objRS
'set connection strings for entire application
strDataPath = server.MapPath("SomeDataba
strConnectString = "Provider=Microsoft.Jet.OL
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;User Id=admin;PASSWORD=;"
if not IsObject("ojbConnection") then
set objConnection=Server.Creat
objConnection.ConnectionTi
objConnection.CommandTimeo
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
set objRS = Server.CreateObject("ADODB
objRS.Open "SELECT fld1, fld2,fld3 FROM tblSomeTable", objConnection,3,3
%>
<html>
<body>
<%Response.Clear%>
<%response.ContentType="ap
<%
Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
Response.Write("<TR>")
do while not objRS.EOF
Response.Write("<TR>")
Response.Write("<TD>" & objRS("fld1")& "</TD>")
Response.Write("<TD>" & objRS("fld3")& "</TD>")
Response.Write("<TD>" & objRS("fld1")& "</TD>")
Response.Write("</TR>")
objRS.MoveNext
loop
%>
</Table>
</body>
</html>
<%
if objRS.State <> 0 then
objRS.Close
end if
set objRS = Nothing
if objConnection.state <> 0 then
objConnection.Close
end if
set objConnection = Nothing
Response.End
%>
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q271/5/72.ASP&NoWebContent=1
This link should help you from my earlier response.
This link should help you from my earlier response.
ASKER
Thanks Jit, but I am not sure that I understand how to specify a new sheet for each row. It looks like it might have something to do with @page but I am not sure how to put this all together.
Fritz the Blank
Fritz the Blank
ASKER
Okay, if I do this, I can get two worksheets, but I still don't know how to place the content of each table on a separate worksheet:
<%@ Language=VBScript %>
<%Response.Buffer=true%>
<%
Response.ContentType = "application/vnd.ms-excel"
%>
<HTML xmlns:x="urn:schemas-micro soft-com:o ffice:exce l">
<HEAD>
<style>
<!--table
@page
{mso-header-data:"&CMultip lication Table\000ADate\: &D\000APage &P";
mso-page-orientation:lands cape;}
br
{mso-data-placement:same-c ell;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sample Workbook</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sample Workbook 2</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>1</TD>
<TD>2</TD>
<TD>3</TD>
</TR>
<TR>
<TD>4</TD>
<TD>5</TD>
<TD>6</TD>
</TR>
<TR>
<TD>7</TD>
<TD>8</TD>
<TD>9</TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TD>10</TD>
<TD>11</TD>
<TD>12</TD>
</TR>
<TR>
<TD>13</TD>
<TD>14</TD>
<TD>15</TD>
</TR>
<TR>
<TD>16</TD>
<TD>17</TD>
<TD>18</TD>
</TR>
</TABLE>
</BODY>
</HTML>
<%@ Language=VBScript %>
<%Response.Buffer=true%>
<%
Response.ContentType = "application/vnd.ms-excel"
%>
<HTML xmlns:x="urn:schemas-micro
<HEAD>
<style>
<!--table
@page
{mso-header-data:"&CMultip
mso-page-orientation:lands
br
{mso-data-placement:same-c
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sample Workbook</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sample Workbook 2</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>1</TD>
<TD>2</TD>
<TD>3</TD>
</TR>
<TR>
<TD>4</TD>
<TD>5</TD>
<TD>6</TD>
</TR>
<TR>
<TD>7</TD>
<TD>8</TD>
<TD>9</TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TD>10</TD>
<TD>11</TD>
<TD>12</TD>
</TR>
<TR>
<TD>13</TD>
<TD>14</TD>
<TD>15</TD>
</TR>
<TR>
<TD>16</TD>
<TD>17</TD>
<TD>18</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Why not just use vbscript?
ASKER
Dan--
This will be part of an asp-based web application where the user will be able to submit a parameter, and the data will be generated from the database. So, using client-side VBScript won't work here. Moreover, I want to avoid using Office Automation as MS recommends against it (and having played around with it, I agree).
Apparently, script similar to that above will work. I just need the little bit of syntax that directs each table to the appropriate works sheet, and all will be well.
Fritz the Blank
This will be part of an asp-based web application where the user will be able to submit a parameter, and the data will be generated from the database. So, using client-side VBScript won't work here. Moreover, I want to avoid using Office Automation as MS recommends against it (and having played around with it, I agree).
Apparently, script similar to that above will work. I just need the little bit of syntax that directs each table to the appropriate works sheet, and all will be well.
Fritz the Blank
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found the answer here at the same time!
https://www.experts-exchange.com/questions/20919841/Pseudo-XML-HTML-Excel-Export.html
https://www.experts-exchange.com/questions/20919841/Pseudo-XML-HTML-Excel-Export.html
ASKER
Upping points before accepting answer
ASKER
Thanks a bunch,
Fritz the Blank
Fritz the Blank
ASKER
BTW, you don't happen to know the syntax for setting the background color of the a row or a cell, do you?
Thanks,
FtB
Thanks,
FtB
"BTW, you don't happen to know the syntax for setting the background color of the a row or a cell, do you?"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexcl2k2/html/odc_xmlss.asp
See <ss:Interior>
B
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexcl2k2/html/odc_xmlss.asp
See <ss:Interior>
B
I don't have the exact code at hand now, but the way to go is through XML. If you save a multiple page Excel file to XML (hit the Save As), and then look through the generated XML with a text editor, you see what i mean.