Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Export Database entries to Excel

LEGEND ,
Jan 23, 2008 Jan 23, 2008

Copy link to clipboard

Copied

HI,

I'm trying to create a way to export database records to Excel. So far, I
have managed to get it working for one row in the database table. However, I
can't work out how to make it loop through all the rows and output the
entire table.

I'm using DM8 / ASP/VBScript

Here is what I have so far :

<%
Dim Excel
Dim Excel_cmd
Dim Excel_numRows

Set Excel_cmd = Server.CreateObject ("ADODB.Command")
Excel_cmd.ActiveConnection = MM_MyDatabase_STRING
Excel_cmd.CommandText = "SELECT * FROM customers ORDER BY id ASC"
Excel_cmd.Prepared = true

Set Excel = Excel_cmd.Execute
Excel_numRows = 0

''// Set the name of the file that you are going to output
FileName = "MySpreadsheet.xls"

''// Build up a regular HTML table (this translates into the rows and cells
in excel)
sData = "<table><tr><th>Name</th><th>Password</th></tr>"

sData = sData & "<tr><td>" & (Excel.Fields.Item("FirstName").Value) &
"</td><td>" & (Excel.Fields.Item("password").Value) & "</td></tr>"

sData = sData & "</table>"

''// Write out the table
response.write sData

''// Set the Header info
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition","attachment; filename=" & FileName

Excel.Close()
Set Excel = Nothing
%>

Can anyone show me what I need to do to get it to look through every record?

Thanks!


TOPICS
Server side applications

Views

207
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2008 Jan 23, 2008

Copy link to clipboard

Copied

LATEST
Hello people,

I managed to figure it out :o)

Sorry to have troubled you.

Minty

"Mintyman" <mintyman@ntlworld.com> wrote in message
news:fn75lo$noi$1@forums.macromedia.com...
> HI,
>
> I'm trying to create a way to export database records to Excel. So far, I
> have managed to get it working for one row in the database table. However,
> I can't work out how to make it loop through all the rows and output the
> entire table.
>
> I'm using DM8 / ASP/VBScript
>
> Here is what I have so far :
>
> <%
> Dim Excel
> Dim Excel_cmd
> Dim Excel_numRows
>
> Set Excel_cmd = Server.CreateObject ("ADODB.Command")
> Excel_cmd.ActiveConnection = MM_MyDatabase_STRING
> Excel_cmd.CommandText = "SELECT * FROM customers ORDER BY id ASC"
> Excel_cmd.Prepared = true
>
> Set Excel = Excel_cmd.Execute
> Excel_numRows = 0
>
> ''// Set the name of the file that you are going to output
> FileName = "MySpreadsheet.xls"
>
> ''// Build up a regular HTML table (this translates into the rows and
> cells in excel)
> sData = "<table><tr><th>Name</th><th>Password</th></tr>"
>
> sData = sData & "<tr><td>" & (Excel.Fields.Item("FirstName").Value) &
> "</td><td>" & (Excel.Fields.Item("password").Value) & "</td></tr>"
>
> sData = sData & "</table>"
>
> ''// Write out the table
> response.write sData
>
> ''// Set the Header info
> Response.ContentType = "application/vnd.ms-excel"
> Response.AddHeader "content-disposition","attachment; filename=" &
> FileName
>
> Excel.Close()
> Set Excel = Nothing
> %>
>
> Can anyone show me what I need to do to get it to look through every
> record?
>
> Thanks!
>
>


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines