Home > WinForms UI Controls > User Manual > Export Grid Data to HTML in C#
Export Data to HTML from GridView C#.NET
By using the Kettic GridView .NET WinForms control, the users can easily export the data in GridView to HTML and create an html format file to viewing in a web browser or MS Word. The HTML data exporting feature is included in the KetticData.dll assembly. To use this method, we should include the Kettic.WinForms.Data and the Kettic.WinForms.UI.Export C# namespaces, which allows us to access to the types contained in KetticData.
How to Export to HTML in C# GridView
To export the grid data to HTML, we need to initialize the ExportToHtml C# class first. And the constructor will take the parameter, KetticGridView, to be exported. The simple C# code below demonstrates the approach of initializing the ExportToHtml object.
When we are going to export the grid data to html file, we can use this property to modify the default file extension, *.html, to the exported result file.
After initializing the ExportToHtml C# class, we can use the following options to determine how to export data: ExportAlways, DoNotExport, and ExportAsHidden. The default setting is the DoNotExport, which will not export the hidden columns and rows to the html file. To accomplish, we need to modify the property of DoNotExport to HiddenColumnOption and HiddenRowOption. The C# code below shows how to set the hidden column option.
The Kettic GridView allows the users to adjust the width of the column in grid. This is achieved through three options. The first option allows the users set fixed width to the specified columns, which will not be effected by the size of the grid columns in the actual Kettic GridView .NET control. The second one is to set fixed width for all columns, which will keep the aspect ratio. The third approach is to leave the column width being calculated automatically based on the content of the cells in the column.
The ExportToHTML C# class is able to export the visual settings to the HTML file. This feature is enabled via modifying the value of EnableAternativeRow property to true. The Kettic GridView only exports the conditional formatting to the HTML file and exports the row height at the default settings. To enable the functionality of exporting visual settings, set the value of ExportVisualSettings property to true as the C# code snippet below.
There is a TableCaption property available to the users modifying the name of the table caption. The following is the C# code to set the table caption 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 HTML now. To export data from grid to HTML, we need to use the ApplyExport method included in the ExportToHtml object. Its valid parameter includes fileName which define the name of the exported file. The following C# code shows how to run the ApplyExport method.
The Kettic GridView C#.NET component allows the users to modify a single cell html element so that we can create formatting html cell for the exported GridView. This is accomplished by using the HtmlCellFormatting event. The C# code below shows how to handle this event.
Moreover, the HtmlTableCaptionFormatting event allows the users to create formatting caption table element on the html. This is accomplished by accessing the TableCaptionElement via event arguments and applying a valid html format. The C# code below demonstrates how to handle the HtmlTableCaptionFormat event.
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