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.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- how to use special characters like '<'
- Request.PathInfo issues and XSS attacks
I either go the CSV route (as described above), or more often these days, I use Infragistics NetAdvantage to generate the file. (The very vast majority of the time where Infragistics is in play, we're just exporting an existing UltraWebGrid, which is essentially a one-LOC solution unless extra formatting tweaks are needed. We could manually generate an Excel/BIFF file as well, but there's rarely a need to.)
If coming from a DataTable:
From a Gridview:
just created a function to export from a web form C# to excel hope it helps others
Here's a report that pulls from a stored procedure. The results are exported to Excel. It uses ADO instead of ADO.NET and the reason why is this line
It does most of the work and isn't available in ado.net.
You can create nicely formatted Excel files using this library, quite easily: http://officehelper.codeplex.com/documentation.
Microsoft Office does not need to be installed on the webserver!
This is a free wrapper around SpreadML--it works great.
http://www.carlosag.net/Tools/ExcelXmlWriter/