Xceed Grid for WinForms v4.3 Documentation
ExcelExporter Properties

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Exporting spreadsheets to Excel > ExcelExporter Properties

The ExcelExporter class provides several properties that affect the appearance of exported spreadsheets.

ColumnHeaderStyle and IncludeColumnHeaders properties

The ColumnHeaderStyle property holds an ExcelStyle object and determines the style to be used for the row of column headers in the exported spreadsheet. By default, its value is null (Nothing in VB.NET), meaning that no style will be used. The IncludeColumnHeaders must be set to true for this property to have an effect.

VB.NET
Copy Code
Imports Xceed.Grid.Exporting

Dim excelExporter1 As New ExcelExporter

Dim excelStyle As New ExcelStyle(Color.Red, Color.White, _

                                 New System.Drawing.Font("Microsoft Sans Serif", 9, _         

                                 FontStyle.Bold), ContentAlignment.MiddleCenter)

excelExporter1.ColumnHeaderStyle = excelStyle

excelExporter1.Export(Me.GridControl1, "d:\test\spreadsheet1.xml")
C#
Copy Code
using Xceed.Grid.Exporting;

ExcelExporter excelExporter1 = new ExcelExporter();

excelExporter1.ColumnHeaderStyle = new ExcelStyle(Color.Red, Color.White,

                                                  new System.Drawing.Font("Microsoft Sans Serif",

                                                  9, FontStyle.Bold), ContentAlignment.MiddleCenter);

excelExporter1.Export(this.gridControl1, @"d:\test\spreadsheet1.xml");

The code above will create a spreadsheet whose column header row has a red background with white lettering (the foreground). 

An ExcelStyle object can also be created by passing a GridElement to its constructor. Doing so and then assigning the ExcelStyle to ColumnHeaderStyle will apply the style of the element as it appears in the grid to the column header. For more details on ExcelStyle, see The ExcelStyle class.

IncludeGridStyles property

When IncludeGridStyles is set to true (the default), the styles, if any, of the grid being exported will be applied to the spreadsheet. Setting this property to false creates spreadsheet with no styles.

DetailGridsMode and IncludeDetailGrids properties

To export detail grids to a spreadsheet, the IncludeDetailGrids property must be set to true (the default). The DetailGridsMode property determines how detail grids will be displayed in the exported spreadsheet. When set to Joined (the default), detail grids are all laid out at the same level, with the name of the column appearing only once in the header row, as can be seen in the following image:

When set to Independent, detail grids will be laid out in the spreadsheet as they appear in the grid; column names will be repeated for each detail grid:

Note: When DetailGridsMode is set to Joined, GridControl.SynchronizeDetailGrids must be set to true. Otherwise, an exception will be thrown. 

When set to false, detail grids are not exported:

RepeatParentData property

A true value in the RepeatParentData property (the default) causes the data of the parent DataRow to be repeated on each of the child rows. An example of this can be see in Figure 1 above. If set to false, blank cells will be inserted in place of the repeated data (see Figure 4 below). The IncludeDetailGrids property must be set to true (the default) for RepeatParentData to have an effect.

By setting RepeatParentData to false and DetailGridsMode to Independent, you can produce a spreadsheet that closely resembles the appearance of Xceed's data grid:

GridLineColor property 

The GridLineColor property is used to control the color of the spreadsheet's grid lines. By default, it is set to Color.Empty.

CellDataFormat property

The CellDataFormat property determines how cells will be displayed in an exported spreadsheet. When set to DisplayText (the default), the cells' content will be treated as text. When set to Value the cells' content will be treated as a value. Specifically, when set to DisplayText, the Type attribute of all cell data will be "String" in the exported spreadsheet: 

<ss:Cell ss:StyleID="xs1">
  <ss:Data ss:Type="String">10248</ss:Data>
</ss:Cell>
 

When set to Value, on the other hand, the Type attribute will be set to "Number": 

<ss:Cell ss:StyleID="xs1">
  <ss:Data ss:Type="Number">10248</ss:Data>
</ss:Cell>
 

All of ExcelExporter's properties can be reset using the corresponding "Reset" methods. For example, the ColumnHeaderStyle property can be reset using the ResetColumnHeaderStyle method, which uses the value returned by the overridable DefaultColumnHeaderStyle.