Excel-export DataGrid or Tree with PFGrid.NET for WinForms
In this
tutorial is described how the Excel-Export is used with PFGrid.NET. It is
assumed that we display the data in the control as TreeListlike that:
Img. 1: PFGrid in TreeList-mode
With
PFGrid.NET it is possible to export the visible hierarchical data to Excel. The
tree is displayed as grouped rows in the worksheet after export:
Img 2: TreeList exported to Excel
How to achieve this
The
Excel-Export is executed using the class XLExport for example in an
eventhandler of a button or an item of a contextmenu:
XLExport xlExport = new XLExport();
xlExport.CreateGroups = cbHierarchy.Checked;
xlExport.ShowColumnHeaders = cbColHeaders.Checked;
xlExport.OpenAfterExport = cbOpenAfterExport.Checked;
xlExport.ExportFile(treeListView, folderBrowserDialog.SelectedPath
+
"\\" + txtFilename.Text
+ ".xls",
txtSheetname.Text);
The class
has the following properties:
|
Property
|
Description
|
|
ShowColumnHeaders : bool
|
Gets or
sets whether the columnheaders of the grid are
visible in the exported Excel-sheet.
|
|
CreateGroups : bool
|
Gets or
sets whether data displayed in the control in Tree-mode is exported with
grouped rows in the exported Excel-Sheet.
|
|
OpenAfterExport : bool
|
Gets or
sets whether the exported file is opened after the export-operation.
Note: If MS-Excel is not installed on
your computer, the file is exported but a Win32Exception will be thrown when trying to open the file.
Set the property to false in this
case.
|
Call the
method ExportFile
to export the data to an Excel-file.