Click here to Skip to main content
Licence 
First Posted 30 Jul 2005
Views 128,594
Bookmarked 57 times

DataSet to Excel in Two steps – with Different Styles

By | 30 Jul 2005 | Article
Cool Component exports DataSet(s) to Excel as Row-wise,Column-wise or Sheet-wise.
 
Part of The SQL Zone sponsored by
See Also

Sample Image - datasettoexcel.jpg

Introduction

This component exports a DataSet to Microsoft Excel. You can also export more than one multiple DataSets at a time. This component handles disposing of Excel objects and cleaning up of memory automatically. So there is no worry of memory leakage!! Just two lines of code to export your DataSet to Excel. This is a free component.

Note: You need Excel to be installed in your system.

Different Styles

Different styles that are available are:

  • Row Wise: Exports each DataTable in the DataSet in row-wise in Excel.
  • Column Wise: Exports each DataTable in the DataSet in column-wise in Excel.
  • Sheet Wise: Exports each DataTable in the DataSet in one worksheet.

Other features and formatting styles

You can set the following:

  • HeaderForeColor
  • HeaderBackColor
  • ItemForeColor
  • ItemBackColor
  • ItemAlternateBackColor
  • FontStyle
  • RowsSpace
  • ColumnSpace
  • TableSpace

Sample Code

Utilities.ExcelExport.Export excel = 
                    new Utilities.ExcelExport.Export();
//Pass your Dataset and Specify the style.
excel.ExportDataToExcel(yourDataSet, 
            Utilities.ExcelExport.ExportStyle.RowWise);

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

Krishna_accent



United Arab Emirates United Arab Emirates

Member

Software Engineer from India,Working in .NET for 2 years.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThe Solution works great but.. PinmemberPooja H Borhade21:02 1 Nov '11  
QuestionWell Done! PinmemberTadesse11:06 21 Jun '11  
GeneralMy vote of 1 Pinmembernavbingo200:52 26 May '11  
QuestionErrors when compiling your source code in Visual Studio 2010 Pinmembermoiztankiwala10:29 10 Jun '10  
AnswerRe: Errors when compiling your source code in Visual Studio 2010 PinmemberTadesse10:52 21 Jun '11  
Generalthank's!, works if Pinmembercheluskis10:03 10 Sep '09  
Questionformulas PinmemberSilentSage3:48 31 Dec '08  
QuestionExcel Export Pinmemberdrshreya9:02 18 Sep '08  
GeneralYou are really the best Pinmemberminatharwat11:55 23 Jan '07  
GeneralTakes ages .... Pinmemberoobject20:19 5 Sep '06  
GeneralRe: Takes ages .... [modified] PinmemberTim Schwallie10:01 30 Jan '07  
GeneralRe: Takes ages .... PinmemberTim Schwallie4:20 31 Jan '07  
GeneralRe: Takes ages .... PinmemberCikaPero21:27 28 Feb '10  
QuestionApplication will not open but process does open PinmemberMariaelisau9:50 6 Jul '06  
GeneralSpecifing Excel File Name PinmemberAli Hussian Al-Faraj21:20 6 Jun '06  
GeneralAssemblies missing Pinmemberlbispo5:30 4 May '06  
GeneralAccess Denied error Pinmembersrichikka23:01 2 May '06  
Hello,
I am getting Access Denied error when i use ur code. i have also checked the permissions for the folder and everything is ok.
Please find below the complete error message for more information on the same.
Access is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.UnauthorizedAccessException: Access is denied.
 
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
 
To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
 
Source Error:
 

Line 138: //excel.ExcelFormattingStyle = formatStyle;
Line 139: //Pass your Dataset and Specify the style..
Line 140: excel.ExportDataToExcel(ds,GetExportStyle());
Line 141:
Line 142:
 
I really appreciate your help on the same.

 
Thanks and Regards
Srikanth. R

GeneralRe: Access Denied error PinmemberMukesh_B22:36 27 Aug '06  
GeneralAccess is denied. Pinmemberoneforall20128:53 28 Apr '06  
QuestionWhere's the article? Pinmemberexhaulted23:03 21 Feb '06  
GeneralAccess is denied PinmemberL. Des Lierres8:01 21 Feb '06  
GeneralRe: Access is denied PinmemberL. Des Lierres14:08 28 Feb '06  
GeneralRe: Access is denied PinmemberL. Des Lierres8:28 29 Jun '06  
GeneralRe: Access is denied PinmemberL. Des Lierres8:29 29 Jun '06  
GeneralThis article is excellent PinmemberTigger9916:39 7 Feb '06  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 31 Jul 2005
Article Copyright 2005 by Krishna_accent
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid