Professional UI Solutions
Site Map   /  Register
 
 
 

Exporting Grid Data

Starting from version 1.3 the base class (GridControlBase) for bound, unbound and virtual grids supports methods for exporting data to a file or a stream in several formats. The supported target formats are listed in the table below.

Target Format Method
Tab-delimited text ExportToTabDelimitedText
Excel XML workbook ExportToExcel
HTML table ExportToHtml

The ExportToExcel method allows you to export data using the Microsoft Excel XML format, which is supported in all versions of Excel starting from Office XP. The advantage of using this format is that you can export data without having to install Microsoft Excel if it is not installed.

The Export demo in the SimpleDemos sample demonstrates how to export data from the bound, unbound and virtual grids using the above described formats.

You can additionally customize exported data using the following features of the export API:

  1. Expand all groups before export. If the grid's contents is grouped and some group rows are collapsed, you can use the expandAllGroups parameter for controlling which rows should be exported. If some row is hidden because its parent group row is collapsed, then expandAllGroups set to true indicates this row will be exported; otherwise, not. Please note that this option does not affect the collapsed/expanded state of the grid itself.
  2. Export the grid header. The exportHeader parameter specifies if column headers should be exported or not.
  3. Export visible columns only. The exportVisibleColumnsOnly parameter allows you to include hidden columns into the result set.
  4. Export a range of rows. You can limit rows of the result set using the startRowIndex and endRowIndex parameters. Here are two simple examples of how you could export a limited range of rows:
[C#]
// Exporting selected rows to a stream:
using(Stream stream = new FileStream(@"c:\text.txt", FileMode.CreateNew))
{
   foreach (int itemIndex in boundGridControl1.SelectedItemIndices)
   {
      boundGridControl1.ExportToTabDelimitedText(stream, false, true, itemIndex, itemIndex);
   }
}
// Export visible rows to a stream:
boundGridControl1.ExportToTabDelimitedText( @"c:\text.txt", 
                          true,
                          true,
                          boundGridControl1.VerticalScrollBar.Value,
                          boundGridControl1.VerticalScrollBar.Value +
                             boundGridControl1.VisibleRowCount - 1 
                         );
[VB.NET]
' Exporting selected rows to a stream:
Using stream As Stream = New FileStream("c:\text.txt", FileMode.CreateNew)
   For Each itemIndex As Integer In boundGridControl1.SelectedItemIndices
      boundGridControl1.ExportToTabDelimitedText(stream, False, True, itemIndex, itemIndex)
   Next itemIndex
End Using
' Export visible rows to a stream:
boundGridControl1.ExportToTabDelimitedText("c:\text.txt", _
     True, _
     True, _
     boundGridControl1.VerticalScrollBar.Value, _
     boundGridControl1.VerticalScrollBar.Value + boundGridControl1.VisibleRowCount - 1)
Back To Top Other Articles...