Click here to Skip to main content
Click here to Skip to main content

Export datatable to XLS/CSV compatible with MS-Office and Open-Office

, 28 Jun 2005
Rate this:
Please Sign up or sign in to vote.
It generates Excel using HTML tags, which are also compatible with Open-Office.

Sample Image - ExportXLSCSV.gif

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vivek Singh - IN
Web Developer
India India
No Biography provided

Comments and Discussions

 
QuestionNice Article Pinmemberswaroop10695-Jun-12 2:10 
GeneralMy vote of 4 PinmemberMorteza Karimian4-Oct-11 19:30 
GeneralMy vote of 5 Pinmemberdelko27-Sep-10 12:39 
GeneralVB Version Pinmemberfrank stuart browne9-Jul-09 17:08 
GeneralRe: VB Version PinmemberMember 420183526-Jan-10 19:13 
GeneralUseful Pinmemberpadmanabhan_ntrjn19-Nov-08 0:19 
Generala bug Pinmembershaorang11-Apr-08 19:44 
GeneralGreat! Pinmembersraap19728-Mar-07 9:47 
GeneralHi Pinmemberashvinidave5-Jan-07 9:54 
GeneralRe: Hi PinmemberVivek Singh - IN8-Jan-07 0:39 
GeneralRe: Hi PinmemberCikaPero19-Sep-11 21:55 
GeneralExport Russian Character Data to CSV or XLS File PinmemberMSJ_PK3-Aug-05 0:03 
GeneralRe: Export Russian Character Data to CSV or XLS File PinmemberVivek Singh - IN3-Aug-05 0:58 
GeneralRe: Export Russian Character Data to CSV or XLS File Pinmembergg423713-Nov-09 1:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 29 Jun 2005
Article Copyright 2005 by Vivek Singh - IN
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid