Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 158689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:43:33+00:00 2026-05-11T10:43:33+00:00

How to create and download excel document using asp.net ? The purpose is to

  • 0

How to create and download excel document using asp.net ?

The purpose is to use xml, linq or whatever to send an excel document to a customer via a browser.

Edit : Use case

The customer load a gridview ( made with ajax framework ) in a browser, the gridview is directly linked to an sql database. I put a button ‘export to excel’ to let customer save this gridview data on his computer ansd i would like to launch a clean download of an excel.

The solutions proposed here are not clean, like send an html document and change the header to excel document etc, i’m searching a simple solution on codeplex right now, i will let you know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:43:34+00:00Added an answer on May 11, 2026 at 10:43 am

    Starter kit

    First i have downloaded the Open XML Format SDK 2.0.

    It comes with 3 useful tools in :

    C:\Program Files\Open XML Format SDK\V2.0\tools

    • DocumentReflector.exe wich auto generate the c# to build a spreadsheet from the code.
    • OpenXmlClassesExplorer.exe display Ecma specification and the class documentation (using an MSDN style format).
    • OpenXmlDiff.exe graphically compare two Open XML files and search for errors.

    I suggest anyone who begin to rename .xlsx to .zip, so you can see the XML files who drive our spreadsheet ( for the example our sheets are in ‘xl\worksheets’ ).


    The code

    Disclaimer : I have stolen all the code from an MSDN technical article ;D

    The following code use an *.xlsx template i made manually to be able to modify it.

    Namespaces references

    using System.IO; using System.Xml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using DocumentFormat.OpenXml;   // Database object         DataClassesDataContext db = new DataClassesDataContext();          // Make a copy of the template file.         File.Copy(@'C:\inetpub\wwwroot\project.Web\Clients\Handlers\oxml-tpl\livreurs.xlsx', @'C:\inetpub\wwwroot\project.Web\Clients\Handlers\oxml-tpl\generated.xlsx', true);          // Open the copied template workbook.          using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(@'C:\inetpub\wwwroot\project.Web\Clients\Handlers\oxml-tpl\generated.xlsx', true))         {             // Access the main Workbook part, which contains all references.             WorkbookPart workbookPart = myWorkbook.WorkbookPart;              // Get the first worksheet.              WorksheetPart worksheetPart = workbookPart.WorksheetParts.ElementAt(2);              // The SheetData object will contain all the data.             SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();              // Begining Row pointer                                    int index = 2;              // Database results             var query = from t in db.Clients select t;              // For each item in the database, add a Row to SheetData.             foreach (var item in query)             {                 // Cell related variable                 string Nom = item.Nom;                  // New Row                 Row row = new Row();                 row.RowIndex = (UInt32)index;                  // New Cell                 Cell cell = new Cell();                 cell.DataType = CellValues.InlineString;                 // Column A1, 2, 3 ... and so on                 cell.CellReference = 'A'+index;                  // Create Text object                 Text t = new Text();                 t.Text = Nom;                  // Append Text to InlineString object                 InlineString inlineString = new InlineString();                 inlineString.AppendChild(t);                  // Append InlineString to Cell                 cell.AppendChild(inlineString);                  // Append Cell to Row                 row.AppendChild(cell);                  // Append Row to SheetData                 sheetData.AppendChild(row);                  // increase row pointer                 index++;                              }              // save             worksheetPart.Worksheet.Save();          } 

    I havent finished yet, my second job is to auto download the spreadsheet after modification.


    Finally, i redirect the user to my generated spredsheet (from my aspx)

     context.Response.Redirect('Oxml-tpl/generated.xlsx'); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Best answers from the Community Traverse a directory tree and… May 12, 2026 at 12:10 am
  • Editorial Team
    Editorial Team added an answer Lucine.net api should help, it's great open source api provided… May 12, 2026 at 12:10 am
  • Editorial Team
    Editorial Team added an answer Initialise the ValueChangedCallback the first time the ItemsSourceCallBack is executed.… May 12, 2026 at 12:10 am

Related Questions

I have a repeatable business process that I execute every week as part of
I'm utilizing the Reporting Services web service to generate a report and allow the
With Excel 2003 and higher it is possible to use the SpreadsheetML format to
Anybody knows how to do this? I need to create a service that will

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.