Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 4

How to export an sqldatasource to Excel file?

This sqldatasource is in an ASPX page. I want to know the VB code to generate an Excel file using the sqldatasource on a click of a button.

1 Answer

Relevance
  • Amit
    Lv 6
    1 decade ago
    Favorite Answer

    First of all you will have to Include the Resources for Microsoft Excel 10/12/14 Office Library

    then

    Dim XL as Excel.Application

    Dim WB as Excel.Workbook

    Dim WS as Excel.Worksheet

    Suppose RsSql is your SQL Record set

    Set XL = new Excel.Application

    set WB = XL.Workbooks.add

    wet WS = WB.Sheets(1)

    for i= 1 to i=RsSql.RecordCount

    for J= 1 to i=RsSql.Fields.count

    ws.cells(i,j) = rssql.Fields(j)-1

    Next

    RsSql.MoveNext

    next

    WB.Save

    xl.close

    set ws = nothing

    set wb = nothing

    xl.quit

    set xl=nothing

    (*.*)a

Still have questions? Get your answers by asking now.