Introduction
Most of the time we get a requirement from the client to export data into .XLS or .CSV format. These are the commonly used solutions by the developer:
Response.ContentType = ="application/vnd.ms-excel"
, this requires Excel to be properly installed on the client machine.
- Now to save the cost, developer can generate the Excel file on the server, and later on download the generated file. But this still requires one license on the server and normally gives a performance problem as the Excel object is unmanaged.
- Using XML/XSLT solution is available here, in which user can generate a file on server and download it without consuming Excel license on the server. Later, the user can modify the file if they have a full Excel version or view in case Excel viewer is installed.
But my client was slighly more conserned about the cost, they were using Open-Office and not the full version of Excel to save the license cost. Which leads to the development of this code library which makes XLS compatible with Open-Office and Excel without using any license.
Using this library code
This library is implemented in C# without using any unmanaged resource and it's very simple to use. Here are the examples:
- To generate Excel:
string fileName =
System.Guid.NewGuid().ToString().Replace("-","") + ".xls";
(new ExportDemo.Libraries.ExcelConvertor()).Convert(
GenerateDataTable(),Server.MapPath("."),fileName);
Response.Redirect(fileName);
- To generate CSV:
string fileName =
System.Guid.NewGuid().ToString().Replace("-","") + ".xls";
(new ExportDemo.Libraries.ExcelConvertor()).Convert(
GenerateDataTable(),Server.MapPath("."),fileName);
Response.Redirect(fileName);
Points of Interest
This component is as free as the .NET Framework library.
History
- Initial version added on 29-June '05.