Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Asp.net

Asp.net

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasetutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RajaMohammed A
    wrote on last edited by
    #1

    how to export the data from stored procedure to excel?

    OriginalGriffO Richard DeemingR L 3 Replies Last reply
    0
    • R RajaMohammed A

      how to export the data from stored procedure to excel?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      What have you tried? Where are you stuck? What help do you need?

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • R RajaMohammed A

        how to export the data from stored procedure to excel?

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        NB: You can't use Office Interop in an ASP.NET application:

        Considerations for server-side Automation of Office[^]

        Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

        Use a tool like EPPlus[^], ClosedXML[^], or The OpenXML SDK[^] to generate an Excel file. For example, EPPlus provides both LoadFromDataReader and LoadFromDataTable methods which you could use to load the data from your query into the Excel file.

        // Load the data from your stored procedure:
        DataTable dt = LoadDataFromStoredProcedure();

        // Export the data to an Excel file:
        var pck = new ExcelPackage();
        var wsDt = pck.Workbook.Worksheets.Add("FromDataTable");
        wsDt.Cells["A1"].LoadFromDataTable(dt, /* PrintHeaders: */ true, TableStyles.Medium9);

        // Send the Excel file back to the user:
        Response.Clear();
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        pck.SaveAs(Response.OutputStream);
        Response.Flush();

        // If you're running this code from a page (.aspx) instead of a generic handler (.ashx):
        Response.SuppressContent = true;
        Context.ApplicationInstance.CompleteRequest();


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • R RajaMohammed A

          how to export the data from stored procedure to excel?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Export as CSV.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups