Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an Excel file in ASP.NET [closed]

I am about to add a section to an ASP.NET app (VB.NET codebehind) that will allow a user to get data returned to them as an Excel file, which I will generate based on database data. While there are several ways of doing this, each has its own drawbacks. How would you return the data? I'm looking for something that's as clean and straightforward as possible.

like image 952
Dan Coates Avatar asked Sep 29 '08 19:09

Dan Coates


People also ask

How can I recover data from Excel in asp net?

Read Data From an Excel File (.xlsx) in ASP.NET Let us get started. Step 1: Open Visual Studio > File > New >Website > Under Templates, click ASP.NET WebSite and choose either Visual C# or Visual Basic as the language. Select a location and click Ok. Step 2: We will create two excel sheets and add them to the project.

Is closed XML free?

ClosedXML is a . NET Library for writing and manipulating the Excel 2007+ files. It's available free on GitHub to use for the commercial project.

What is the difference between OpenXml and ClosedXML?

Macros – ClosedXml doesn't support macros as its base library OpenXml also doesn't support it. Embedding – We cannot embed any file into Excel using ClosedXml, no APIs built for that, so some features of OpenXml still need to be implemented. Charts – No functionality related to charting is present.

Is ClosedXML open source?

ClosedXML is an open source library created based on OpenXmlSdk. It's more user friendly. ClosedXML is a . NET library for reading, manipulating and writing Excel 2007+ (.


1 Answers

CSV

Pros:

  • Simple

Cons:

  • It may not work in other locales or in different Excel configurations (i.e. List separator)
  • Can't apply formatting, formulas, etc

HTML

Pros:

  • Still pretty Simple
  • Supports simple formating and formulas

Cons:

  • You have to name the file as xls and Excel may warn you about opening a non native Excel file
  • One worksheet per workbook

OpenXML (Office 2007 .XLSX)

Pros:

  • Native Excel format
  • Supports all Excel features
  • Do not require an install copy of Excel
  • Can generate Pivot tables
  • Can be generated using open source project EPPlus

Cons:

  • Limited compatibility outside Excel 2007 (shouldn't be a problem nowadays)
  • Complicated unless you're using a third party component

SpreadSheetML (open format XML)

Pros:

  • Simple compared to native Excel formats
  • Supports most Excel features: formating, styles, formulas, multiple sheets per workbook
  • Excel does not need to be installed to use it
  • No third party libraries needed - just write out your xml
  • Documents can be opened by Excel XP/2003/2007

Cons:

  • Lack of good documentation
  • Not supported in older versions of Excel (pre-2000)
  • Write-only, in that once you open it and make changes from Excel it's converted to native Excel.

XLS (generated by third party component)

Pros:

  • Generate native Excel file with all the formating, formulas, etc.

Cons:

  • Cost money
  • Add dependencies

COM Interop

Pros:

  • Uses native Microsoft libraries
  • Read support for native documents

Cons:

  • Very slow
  • Dependency/version matching issues
  • Concurrency/data integrity issues for web use when reading
  • Very slow
  • Scaling issues for web use (different from concurrency): need to create many instances of heavy Excel app on the server
  • Requires Windows
  • Did I mention that it's slow?
like image 140
Eduardo Molteni Avatar answered Sep 18 '22 21:09

Eduardo Molteni