Home > WinForms UI Controls > User Manual > Export Grid Data to Excel in C#
GridView Data Exporting to Excel in C#.NET
The Kettic GridView .NET component provides the support of exporting data from grid to Excel file. This feature neednât the MS Office installation, however, allows the exported Excel file being read in MS Excel spreadsheet 2003 and higher versions. To export the data to the Excel, we need to use the KetticData.dll assembly and include the C# namespaces to access to the types contained in KetticData, like Kettic.WinForms.Data and Kettic.WinForms.UI.Export
How to Export Data from Grid to Excel in C#
To export the data from grid to Excel, we need to use the ExcelML format, which hold the exported data. So we need to initialize the ExportToExcelML C# class first. And the constructor will take the parameter, KetticGridView. The simple C# code below shows that how to initialize the ExportToExcelML object.
After initializing the ExportToExcelML C# class, we can use the following options to determine how to export data: ExportAlways, DoNotExport, and ExportAsHidden. The default setting is the ExportAsHidden, which allows the users to hide the columns and rows. These options can be achieved through HiddenColumnOption and HiddenRowOption properties. If the users do not want to export the hidden columns or rows, they can set the two properties to DoNotExport. The C# code below is to set the hidden column option.
The ExcelML method is able to export the themes to the Excel file. This feature is enabled through changing the value of EnableAternativeRow property to true. The Kettic GridView is able to export all conditional formatting to the Excel file. To enable the functionality of exporting visual settings, set the value of ExportVisualSettings property to ture.
The Kettic GridView control provides the support of splitting data on separate sheets when the number of rows is larger than Excel maximum. This is accomplished by setting the SheetMaxRows property. The following C# code demonstrates how to achieve this.
There is a SheetName property available to the users changing the name of the MS Excel Sheet. When the data exceeds a single sheet, the export method adds index to the names of the new sheet. The following is the C# code to set the SheetName property
The Kettic GridView .NET control offers the SummariesExportOption property to specify how to export summary items. There are four options available for selecting: ExportAll, ExportOnlyTop, ExportOnlyBottom, and DoNotExport. The default setting is ExportAll. The C# code below shows how to set the SummariesExportOption property.
After setting the above properties, we can export the data from grid to Excel now. To export data from grid to Excel, we need to use the ApplyExport method included in the ExportToExcelML object. Its valid parameter includes fileName which define the name of the exported file.
UI Controlsfor Windows Forms.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls
WinForms Buttons UI Control WinForms Calendar UI ControlWinForms Carousel UI ControlWinForms Chart UI ControlWinForms Clock UI ControlCommandBar UI ControlWinForms Dock UI ControlDesktop Alert UI ControlDropDown List UI ControlWinForms Editor UI ControlForms and Dialogs UI ControlWinForms GridView UI ControlGridView - Get Started in C#GridView - PropertiesGridView - ColumnGridView - RowGridView - CellsGridView - EditorsGridView - Context MenuGridView - Populating with DataGridView - Hierarchical GridGridView - SelectionGridView - ScrollingGridView - SortingGridView - GroupingGridView - FilteringGridView - Expression EditorInsert/ Update/ Delete RecordsGridView - View DefinitionTableColumn GroupGridView - Exporting DataExport to ExcelExport Data in a Group to ExcelExport to CSVExport to HTMLExport to PDFStyling and AppearanceThemeImageAlternating Row ColorGridView - LocalizationSave and Load LayoutGridView - Print SupportPrint StylePrint EventsWinForms ListView UI ControlWinForms Menu UI ControlWinForms ComboBox UI ControlWinForms PageView UI ControlPanels and Labels UI ControlWinForms Panorama UI ControlWinForms PDFViewer UI ControlWinForms Property Grid UI ControlWinForms Ribbon UI ControlWinForms PivotGrid UI ControlWinForms RichTextBox UI ControlWinForms Rotator UI ControlWinForms Scheduler UI ControlWinForms Shortcuts UI ControlWinForms SpellChecker UI ControlWinForms Track & Status UI ControlWinForms TreeView UI ControlWinForms Wizard UI ControlWinForms Test UI ControlWinForms Theme UI Control