Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: RE: How To Display ASP Data As An Excel Spreadshe- et


Message #1 by "Fagan, Karen A (ARINC)" <FaganKA@n...> on Thu, 19 Jul 2001 16:31:14 -0400
Hi Susan,



   Did you ever get this to work?  I too am very interested in taking

information from a database and being able to save it as a spreadsheet.

Some of my users need their information in spreadsheet format for their 

own

use.



   Would appreciate any help/advice that you could give me.  I'm still

learning but it is coming starting to come together for me.  Thanks for 

you

advice a while ago on the recommendations on the WROX Beginning ASP

(excellent book!) and the SAMS teach yourself ASP in 24 hours.   I 

bought

both books and they are definitely helping me out!!





Thanks again,

Karen





-----Original Message-----

From: Susan Henesy [mailto:susan.henesy@w...]

Sent: Tuesday, June 05, 2001 6:26 PM

To: ASP Databases

Subject: [asp_databases] How To Display ASP Data As An Excel 

Spreadsheet





Hello, experts!



I've seen a few posts about displaying ASP data as an Excel 

Spreadsheet,

available for easy downloading by users, but I haven't really seen a

simple explanation as to how it can be done.



A coworker of mine has successfully done this, and he sent me the

following incredibly simple explanation:



----------------------------------------------------

All we do is put the following code above the HTML header file in our 

.asp

pages:



Response.ContentType =3D "application/vnd.ms-excel"



Then use html tables to format our output.  The result is an Excel

spreadsheet in the browser that can be saved by the user.

----------------------------------------------------



The only problem is that when I try to do this, I get a nasty ASP 

message,

which states:



**********************************************

Response object error 'ASP 0156 : 80004005'



Header Error



/databases/webpages/export.asp, line 7



The HTTP headers are already written to the client browser. Any HTTP

header modifications must be made before writing page content.

**********************************************



I am not exactly sure where to put the command suggested by my coworker 

--

and he's not around to answer my questions, <POUT>!



I've included the code from my page in its entirety.  It's pretty 

simple

stuff.  I've tried moving <% Response.ContentType =3D 

"application/vnd.ms-

excel" %> *everywhere* -- in the header, before the header, etc., and 

all

I get are bothersome error messages!!  Can anyone figure out how this 

is

supposed to work?  I'm sure I wouldn't be the only person who'd 

appreciate

knowing this trick! 



Thanks in advance,

Susan (my code follows below):

----------------------------------------------

<%@ LANGUAGE=3DVBScript %>

<!-- #include file=3D"../../IncFiles/Adovbs.inc" -->

<!-- #include file=3D"../../IncFiles/ProductionErrorHandler.inc" -->



<% Response.ContentType=3D"application/vnd.ms-excel" %>



<html>



<head>

<title>Export Product Details To Excel</title>



<!-- #include file=3D"../../IncFiles/DatabaseConnect.inc" -->

<%

'Check for errors

Call CheckForErrors(objConn)



Dim objRS

Dim oHeader



Set objRS =3D CreateObject("ADODB.Recordset")

objRS.Open "spWebExportResults", objConn, adOpenKeySet, adLockReadOnly, 



adCmdStoredProc

'Check for errors

Call CheckForErrors(objConn)



%>



</head>



<body bgcolor=3D"#FFFFFF">

<%

Response.Write "<TABLE BORDER=3D'1'><TR>"



'Create a header row

For Each oHeader in objRS.Fields

	Response.Write "<TH>" & oHeader.Name & "</TH>"

Next

Response.Write "</TR><TR><TD>"



'Create data rows

Response.Write objRS.GetString(,,"</TD><TD>","</TD></TR><TR><TD>", 

"=A0")

Response.Write "</TD></TR></TABLE>"



objRS.Close

Set objRS =3D Nothing

%>



</body>

</html>

--------------------------------------

Message #2 by "Tomm Matthis" <matthis@b...> on Fri, 20 Jul 2001 09:32:12 -0400
Write the data out to a CSV file (Comma Seperated Values)... Excel can 

open this natively.

If you need to format the cells, then you will need a 3rd party 

component, or Excel installed on the websever and invoke it as needed 

via COM (but not a good idea if you have lots of users because of the 

memory requirements.)



-- Tomm



> -----Original Message-----

> From: Fagan, Karen A (ARINC) [mailto:FaganKA@n...]

> Sent: Thursday, July 19, 2001 4:31 PM

> To: ASP Databases

> Subject: [asp_databases] RE: How To Display ASP Data As An Excel

> Spreadshe et

>

>

> Hi Susan,

>

>    Did you ever get this to work?  I too am very interested in taking

> information from a database and being able to save it as a 

spreadsheet.

> Some of my users need their information in spreadsheet format for

> their own

> use.

>

>    Would appreciate any help/advice that you could give me.  I'm still

> learning but it is coming starting to come together for me. 

> Thanks for you

> advice a while ago on the recommendations on the WROX Beginning ASP

> (excellent book!) and the SAMS teach yourself ASP in 24 hours.   I 

bought

> both books and they are definitely helping me out!!

>

>

> Thanks again,

> Karen

>

>

> -----Original Message-----

> From: Susan Henesy [mailto:susan.henesy@w...]

> Sent: Tuesday, June 05, 2001 6:26 PM

> To: ASP Databases

> Subject: [asp_databases] How To Display ASP Data As An Excel 

Spreadsheet

>

>

> Hello, experts!

>

> I've seen a few posts about displaying ASP data as an Excel 

Spreadsheet,

> available for easy downloading by users, but I haven't really seen a

> simple explanation as to how it can be done.

>

> A coworker of mine has successfully done this, and he sent me the

> following incredibly simple explanation:

>

> ----------------------------------------------------

> All we do is put the following code above the HTML header file in

> our .asp

> pages:

>

> Response.ContentType =3D "application/vnd.ms-excel"

>

> Then use html tables to format our output.  The result is an Excel

> spreadsheet in the browser that can be saved by the user.

> ----------------------------------------------------

>

> The only problem is that when I try to do this, I get a nasty ASP

> message,

> which states:

>

> **********************************************

> Response object error 'ASP 0156 : 80004005'

>

> Header Error

>

> /databases/webpages/export.asp, line 7

>

> The HTTP headers are already written to the client browser. Any HTTP

> header modifications must be made before writing page content.

> **********************************************

>

> I am not exactly sure where to put the command suggested by my

> coworker --

> and he's not around to answer my questions, <POUT>!

>

> I've included the code from my page in its entirety.  It's pretty 

simple

> stuff.  I've tried moving <% Response.ContentType =3D 

"application/vnd.ms-

> excel" %> *everywhere* -- in the header, before the header, etc., and 

all

> I get are bothersome error messages!!  Can anyone figure out how this 

is

> supposed to work?  I'm sure I wouldn't be the only person who'd

> appreciate

> knowing this trick! 

>

> Thanks in advance,

> Susan (my code follows below):

> ----------------------------------------------

> <%@ LANGUAGE=3DVBScript %>

> <!-- #include file=3D"../../IncFiles/Adovbs.inc" -->

> <!-- #include file=3D"../../IncFiles/ProductionErrorHandler.inc" -->

>

> <% Response.ContentType=3D"application/vnd.ms-excel" %>

>

> <html>

>

> <head>

> <title>Export Product Details To Excel</title>

>

> <!-- #include file=3D"../../IncFiles/DatabaseConnect.inc" -->

> <%

> 'Check for errors

> Call CheckForErrors(objConn)

>

> Dim objRS

> Dim oHeader

>

> Set objRS =3D CreateObject("ADODB.Recordset")

> objRS.Open "spWebExportResults", objConn, adOpenKeySet, 

adLockReadOnly,

> adCmdStoredProc

> 'Check for errors

> Call CheckForErrors(objConn)

>

> %>

>

> </head>

>

> <body bgcolor=3D"#FFFFFF">

> <%

> Response.Write "<TABLE BORDER=3D'1'><TR>"

>

> 'Create a header row

> For Each oHeader in objRS.Fields

>  Response.Write "<TH>" & oHeader.Name & "</TH>"

> Next

> Response.Write "</TR><TR><TD>"

>

> 'Create data rows

> Response.Write objRS.GetString(,,"</TD><TD>","</TD></TR><TR><TD>", 

"=A0")

> Response.Write "</TD></TR></TABLE>"

>

> objRS.Close

> Set objRS =3D Nothing

> %>

>

> </body>

> </html>

> --------------------------------------

>

Message #3 by Ludwig Brandon-FBL017C <Brandon.Ludwig@m...> on Fri, 20 Jul 2001 09:43:49 -0400
This error message is because you have to put the content type as the first

thing on the page itself...no other code can be above it. 



Brandon Ludwig

Brandon.Ludwig@M...





> ----------------------------------------------------

> All we do is put the following code above the HTML header file in 

> our .asp 

> pages:

> 

> Response.ContentType = "application/vnd.ms-excel"

> 

> Then use html tables to format our output.  The result is an Excel 

> spreadsheet in the browser that can be saved by the user.

> ----------------------------------------------------

> 

> The only problem is that when I try to do this, I get a nasty ASP 

> message, 

> which states:

> 

> **********************************************

> Response object error 'ASP 0156 : 80004005' 

> 

> Header Error 

> 

> /databases/webpages/export.asp, line 7 

> 

> The HTTP headers are already written to the client browser. Any HTTP 

> header modifications must be made before writing page content.

> **********************************************

> 

> I am not exactly sure where to put the command suggested by my 

> coworker -- 

> and he's not around to answer my questions, <POUT>!

> 



Message #4 by "Grant I" <giswim1@a...> on Fri, 20 Jul 2001 14:47:04
Karen



I just built a page to add to my site exporting db query results to Excel 

(yesterday in fact).  I didn't do it the way Susan was (i.e. using 

headers).  Instead I used excel application object.  The method for 

populating the cells is actually quite similar to populating a table with 

db results.  If you would like, I can e-mail you the code.



> Hi Susan,

> 

>    Did you ever get this to work?  I too am very interested in taking

> information from a database and being able to save it as a spreadsheet.

> Some of my users need their information in spreadsheet format for their 

> own

> use.

> 

>    Would appreciate any help/advice that you could give me.  I'm still

> learning but it is coming starting to come together for me.  Thanks for 

> you

> advice a while ago on the recommendations on the WROX Beginning ASP

> (excellent book!) and the SAMS teach yourself ASP in 24 hours.   I 

> bought

> both books and they are definitely helping me out!!

> 

> 

> Thanks again,

> Karen

> 

> 

> -----Original Message-----

> From: Susan Henesy [mailto:susan.henesy@w...]

> Sent: Tuesday, June 05, 2001 6:26 PM

> To: ASP Databases

> Subject: [asp_databases] How To Display ASP Data As An Excel 

> Spreadsheet

> 

> 

> Hello, experts!

> 

> I've seen a few posts about displaying ASP data as an Excel 

> Spreadsheet,

> available for easy downloading by users, but I haven't really seen a

> simple explanation as to how it can be done.

> 

> A coworker of mine has successfully done this, and he sent me the

> following incredibly simple explanation:

> 

> ----------------------------------------------------

> All we do is put the following code above the HTML header file in our 

> .asp

> pages:

> 

> Response.ContentType =3D "application/vnd.ms-excel"

> 

> Then use html tables to format our output.  The result is an Excel

> spreadsheet in the browser that can be saved by the user.

> ----------------------------------------------------

> 

> The only problem is that when I try to do this, I get a nasty ASP 

> message,

> which states:

> 

> **********************************************

> Response object error 'ASP 0156 : 80004005'

> 

> Header Error

> 

> /databases/webpages/export.asp, line 7

> 

> The HTTP headers are already written to the client browser. Any HTTP

> header modifications must be made before writing page content.

> **********************************************

> 

> I am not exactly sure where to put the command suggested by my coworker 

> --

> and he's not around to answer my questions, <POUT>!

> 

> I've included the code from my page in its entirety.  It's pretty 

> simple

> stuff.  I've tried moving <% Response.ContentType =3D 

> "application/vnd.ms-

> excel" %> *everywhere* -- in the header, before the header, etc., and 

> all

> I get are bothersome error messages!!  Can anyone figure out how this 

> is

> supposed to work?  I'm sure I wouldn't be the only person who'd 

> appreciate

> knowing this trick! 

> 

> Thanks in advance,

> Susan (my code follows below):

> ----------------------------------------------

> <%@ LANGUAGE=3DVBScript %>

> <!-- #include file=3D"../../IncFiles/Adovbs.inc" -->

> <!-- #include file=3D"../../IncFiles/ProductionErrorHandler.inc" -->

> 

> <% Response.ContentType=3D"application/vnd.ms-excel" %>

> 

> <html>

> 

> <head>

> <title>Export Product Details To Excel</title>

> 

> <!-- #include file=3D"../../IncFiles/DatabaseConnect.inc" -->

> <%

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> Dim objRS

> Dim oHeader

> 

> Set objRS =3D CreateObject("ADODB.Recordset")

> objRS.Open "spWebExportResults", objConn, adOpenKeySet, adLockReadOnly, 

> 

> adCmdStoredProc

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> %>

> 

> </head>

> 

> <body bgcolor=3D"#FFFFFF">

> <%

> Response.Write "<TABLE BORDER=3D'1'><TR>"

> 

> 'Create a header row

> For Each oHeader in objRS.Fields

> 	Response.Write "<TH>" & oHeader.Name & "</TH>"

> Next

> Response.Write "</TR><TR><TD>"

> 

> 'Create data rows

> Response.Write objRS.GetString(,,"</TD><TD>","</TD></TR><TR><TD>", 

> "=A0")

> Response.Write "</TD></TR></TABLE>"

> 

> objRS.Close

> Set objRS =3D Nothing

> %>

> 

> </body>

> </html>

> --------------------------------------

Message #5 by "Fagan, Karen A (ARINC)" <FaganKA@n...> on Mon, 23 Jul 2001 09:16:10 -0400
Hi,



  That sounds exactly like what I want to do.  It  would be great if you

could e-mail your code.  It 

certainly would help me out alot.  



  Thanks so much.....



Karen



-----Original Message-----

From: Grant I [mailto:giswim1@a...]

Sent: Friday, July 20, 2001 10:47 AM

To: ASP Databases

Subject: [asp_databases] RE: How To Display ASP Data As An Excel

Spreadshe- et





Karen



I just built a page to add to my site exporting db query results to Excel 

(yesterday in fact).  I didn't do it the way Susan was (i.e. using 

headers).  Instead I used excel application object.  The method for 

populating the cells is actually quite similar to populating a table with 

db results.  If you would like, I can e-mail you the code.



> Hi Susan,

> 

>    Did you ever get this to work?  I too am very interested in taking

> information from a database and being able to save it as a spreadsheet.

> Some of my users need their information in spreadsheet format for their 

> own

> use.

> 

>    Would appreciate any help/advice that you could give me.  I'm still

> learning but it is coming starting to come together for me.  Thanks for 

> you

> advice a while ago on the recommendations on the WROX Beginning ASP

> (excellent book!) and the SAMS teach yourself ASP in 24 hours.   I 

> bought

> both books and they are definitely helping me out!!

> 

> 

> Thanks again,

> Karen

> 

> 

> -----Original Message-----

> From: Susan Henesy [mailto:susan.henesy@w...]

> Sent: Tuesday, June 05, 2001 6:26 PM

> To: ASP Databases

> Subject: [asp_databases] How To Display ASP Data As An Excel 

> Spreadsheet

> 

> 

> Hello, experts!

> 

> I've seen a few posts about displaying ASP data as an Excel 

> Spreadsheet,

> available for easy downloading by users, but I haven't really seen a

> simple explanation as to how it can be done.

> 

> A coworker of mine has successfully done this, and he sent me the

> following incredibly simple explanation:

> 

> ----------------------------------------------------

> All we do is put the following code above the HTML header file in our 

> .asp

> pages:

> 

> Response.ContentType =3D "application/vnd.ms-excel"

> 

> Then use html tables to format our output.  The result is an Excel

> spreadsheet in the browser that can be saved by the user.

> ----------------------------------------------------

> 

> The only problem is that when I try to do this, I get a nasty ASP 

> message,

> which states:

> 

> **********************************************

> Response object error 'ASP 0156 : 80004005'

> 

> Header Error

> 

> /databases/webpages/export.asp, line 7

> 

> The HTTP headers are already written to the client browser. Any HTTP

> header modifications must be made before writing page content.

> **********************************************

> 

> I am not exactly sure where to put the command suggested by my coworker 

> --

> and he's not around to answer my questions, <POUT>!

> 

> I've included the code from my page in its entirety.  It's pretty 

> simple

> stuff.  I've tried moving <% Response.ContentType =3D 

> "application/vnd.ms-

> excel" %> *everywhere* -- in the header, before the header, etc., and 

> all

> I get are bothersome error messages!!  Can anyone figure out how this 

> is

> supposed to work?  I'm sure I wouldn't be the only person who'd 

> appreciate

> knowing this trick! 

> 

> Thanks in advance,

> Susan (my code follows below):

> ----------------------------------------------

> <%@ LANGUAGE=3DVBScript %>

> <!-- #include file=3D"../../IncFiles/Adovbs.inc" -->

> <!-- #include file=3D"../../IncFiles/ProductionErrorHandler.inc" -->

> 

> <% Response.ContentType=3D"application/vnd.ms-excel" %>

> 

> <html>

> 

> <head>

> <title>Export Product Details To Excel</title>

> 

> <!-- #include file=3D"../../IncFiles/DatabaseConnect.inc" -->

> <%

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> Dim objRS

> Dim oHeader

> 

> Set objRS =3D CreateObject("ADODB.Recordset")

> objRS.Open "spWebExportResults", objConn, adOpenKeySet, adLockReadOnly, 

> 

> adCmdStoredProc

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> %>

> 

> </head>

> 

> <body bgcolor=3D"#FFFFFF">

> <%

> Response.Write "<TABLE BORDER=3D'1'><TR>"

> 

> 'Create a header row

> For Each oHeader in objRS.Fields

>  Response.Write "<TH>" & oHeader.Name & "</TH>"

> Next

> Response.Write "</TR><TR><TD>"

> 

> 'Create data rows

> Response.Write objRS.GetString(,,"</TD><TD>","</TD></TR><TR><TD>", 

> "=A0")

> Response.Write "</TD></TR></TABLE>"

> 

> objRS.Close

> Set objRS =3D Nothing

> %>

> 

> </body>

> </html>

> --------------------------------------

Message #6 by "Fagan, Karen A (ARINC)" <FaganKA@n...> on Wed, 25 Jul 2001 10:38:54 -0400
Hi Grant,



   I am very interested in how you have your db query and Excel set up.  I

was wondering

if you might have a chance to e-mail me your code.  I would definitely

appreciate it

and think that it would help me out tremendously.





Thanks so much,

Karen









-----Original Message-----

From: Grant I [mailto:giswim1@a...]

Sent: Friday, July 20, 2001 10:47 AM

To: ASP Databases

Subject: [asp_databases] RE: How To Display ASP Data As An Excel

Spreadshe- et





Karen



I just built a page to add to my site exporting db query results to Excel 

(yesterday in fact).  I didn't do it the way Susan was (i.e. using 

headers).  Instead I used excel application object.  The method for 

populating the cells is actually quite similar to populating a table with 

db results.  If you would like, I can e-mail you the code.



> Hi Susan,

> 

>    Did you ever get this to work?  I too am very interested in taking

> information from a database and being able to save it as a spreadsheet.

> Some of my users need their information in spreadsheet format for their 

> own

> use.

> 

>    Would appreciate any help/advice that you could give me.  I'm still

> learning but it is coming starting to come together for me.  Thanks for 

> you

> advice a while ago on the recommendations on the WROX Beginning ASP

> (excellent book!) and the SAMS teach yourself ASP in 24 hours.   I 

> bought

> both books and they are definitely helping me out!!

> 

> 

> Thanks again,

> Karen

> 

> 

> -----Original Message-----

> From: Susan Henesy [mailto:susan.henesy@w...]

> Sent: Tuesday, June 05, 2001 6:26 PM

> To: ASP Databases

> Subject: [asp_databases] How To Display ASP Data As An Excel 

> Spreadsheet

> 

> 

> Hello, experts!

> 

> I've seen a few posts about displaying ASP data as an Excel 

> Spreadsheet,

> available for easy downloading by users, but I haven't really seen a

> simple explanation as to how it can be done.

> 

> A coworker of mine has successfully done this, and he sent me the

> following incredibly simple explanation:

> 

> ----------------------------------------------------

> All we do is put the following code above the HTML header file in our 

> .asp

> pages:

> 

> Response.ContentType =3D "application/vnd.ms-excel"

> 

> Then use html tables to format our output.  The result is an Excel

> spreadsheet in the browser that can be saved by the user.

> ----------------------------------------------------

> 

> The only problem is that when I try to do this, I get a nasty ASP 

> message,

> which states:

> 

> **********************************************

> Response object error 'ASP 0156 : 80004005'

> 

> Header Error

> 

> /databases/webpages/export.asp, line 7

> 

> The HTTP headers are already written to the client browser. Any HTTP

> header modifications must be made before writing page content.

> **********************************************

> 

> I am not exactly sure where to put the command suggested by my coworker 

> --

> and he's not around to answer my questions, <POUT>!

> 

> I've included the code from my page in its entirety.  It's pretty 

> simple

> stuff.  I've tried moving <% Response.ContentType =3D 

> "application/vnd.ms-

> excel" %> *everywhere* -- in the header, before the header, etc., and 

> all

> I get are bothersome error messages!!  Can anyone figure out how this 

> is

> supposed to work?  I'm sure I wouldn't be the only person who'd 

> appreciate

> knowing this trick! 

> 

> Thanks in advance,

> Susan (my code follows below):

> ----------------------------------------------

> <%@ LANGUAGE=3DVBScript %>

> <!-- #include file=3D"../../IncFiles/Adovbs.inc" -->

> <!-- #include file=3D"../../IncFiles/ProductionErrorHandler.inc" -->

> 

> <% Response.ContentType=3D"application/vnd.ms-excel" %>

> 

> <html>

> 

> <head>

> <title>Export Product Details To Excel</title>

> 

> <!-- #include file=3D"../../IncFiles/DatabaseConnect.inc" -->

> <%

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> Dim objRS

> Dim oHeader

> 

> Set objRS =3D CreateObject("ADODB.Recordset")

> objRS.Open "spWebExportResults", objConn, adOpenKeySet, adLockReadOnly, 

> 

> adCmdStoredProc

> 'Check for errors

> Call CheckForErrors(objConn)

> 

> %>

> 

> </head>

> 

> <body bgcolor=3D"#FFFFFF">

> <%

> Response.Write "<TABLE BORDER=3D'1'><TR>"

> 

> 'Create a header row

> For Each oHeader in objRS.Fields

>  Response.Write "<TH>" & oHeader.Name & "</TH>"

> Next

> Response.Write "</TR><TR><TD>"

> 

> 'Create data rows

> Response.Write objRS.GetString(,,"</TD><TD>","</TD></TR><TR><TD>", 

> "=A0")

> Response.Write "</TD></TR></TABLE>"

> 

> objRS.Close

> Set objRS =3D Nothing

> %>

> 

> </body>

> </html>

> --------------------------------------


  Return to Index