Back to Devexpress

PivotGridOptionsPrint.MergeColumnFieldValues Property

corelibraries-devexpress-dot-xtrapivotgrid-dot-pivotgridoptionsprint-5b6eabe4.md

latest6.7 KB
Original Source

PivotGridOptionsPrint.MergeColumnFieldValues Property

Gets or sets whether the values of outer column fields are merged when a pivot grid is printed.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.PivotGrid.v25.2.Core.dll

NuGet Packages : DevExpress.PivotGrid.Core, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(true)]
public bool MergeColumnFieldValues { get; set; }
vb
<DefaultValue(True)>
Public Property MergeColumnFieldValues As Boolean

Property Value

TypeDefaultDescription
Booleantrue

true if the values of outer column fields are merged; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to MergeColumnFieldValues
PivotGridControl

.OptionsPrint .MergeColumnFieldValues

|

Remarks

If this property is set to true , the field values of outer column fields are merged when a pivot grid is printed (in the same way as the outer field values are displayed in the control on a form). Otherwise, merged cells are split into small cells and an empty cell duplicates the original cell’s value.

The MergeColumnFieldValues property is used to customize the Pivot Grid’s export settings in WYSIWYG export mode. This property is not in effect in data-aware export mode. To apply the same settings in data-aware mode, customize the control’s PivotXlsExportOptions or PivotXlsxExportOptions export settings as in the example below.

Use the PivotGridOptionsPrint.MergeRowFieldValues property to specify whether to merge the outer row field values.

Example

WYSIWYG Mode

The following example illustrates how to disable merged values of outer column fields in the exported Excel document. Use the ExportType property to enable the WYSIWYG export mode and set the MergeColumnFieldValues property to false.

csharp
private void btnExportToWYSIWYG_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e){
    PivotXlsxExportOptions pivotExportOptions = new DevExpress.XtraPivotGrid.PivotXlsxExportOptions();
    pivotExportOptions.ExportType = DevExpress.Export.ExportType.WYSIWYG;
    pivotGridControl1.OptionsPrint.MergeColumnFieldValues = false;
    var path = "D:/temp/pivot-grid-data.xlsx";
    pivotGridControl1.ExportToXlsx(path, pivotExportOptions);
}
vb
Private Sub btnExportToWYSIWYG_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
    Dim pivotExportOptions As PivotXlsxExportOptions = New DevExpress.XtraPivotGrid.PivotXlsxExportOptions()
    pivotExportOptions.ExportType = DevExpress.Export.ExportType.WYSIWYG
    pivotGridControl1.OptionsPrint.MergeColumnFieldValues = False
    Dim path = "D:/temp/pivot-grid-data.xlsx"
    pivotGridControl1.ExportToXlsx(path, pivotExportOptions)
End Sub

Data-Aware Mode

When you export data in Excel format, the exporting mechanism does not duplicate values of outer column fields for each child field value in the exported document. To duplicate field value for every empty cell of outer column fields, handle the PivotXlsExportOptions.CustomizeCell event and fill empty cells with the values, as illustrated in the code snippet below. The resulting table looks similar to the table exported in the WYSIWYG mode with the disabled MergeColumnFieldValues property.

csharp
private void btnExportToDataAware_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    PivotXlsxExportOptions options = new PivotXlsxExportOptions();
    options.CustomizeCell += options_CustomizeCell;
    options.ExportType = DevExpress.Export.ExportType.DataAware;
    options.AllowCellMerge = DevExpress.Utils.DefaultBoolean.False;
    string path = "D:/temp/pivot-grid-data.xlsx";
    pivotGridControl1.ExportToXlsx(path, options);
}
void options_CustomizeCell(CustomizePivotCellEventArgs e) {
    if (e.ExportArea == PivotExportArea.Column && e.ValueItemInfo.Field != null 
    && e.Value == null && e.ValueItemInfo.Value != null) { 
        e.Value = e.ValueItemInfo.Field.GetValueText(e.ValueItemInfo.Value);
        e.Handled = true;
    }
}
vb
Private Sub btnExportToDataAware_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
    Dim options As New PivotXlsxExportOptions()
    AddHandler options.CustomizeCell, AddressOf options_CustomizeCell
    options.ExportType = DevExpress.Export.ExportType.DataAware
    options.AllowCellMerge = DevExpress.Utils.DefaultBoolean.False
    Dim path As String = "D:/temp/pivot-grid-data.xlsx"
    pivotGridControl1.ExportToXlsx(path, options)
End Sub
Private Sub options_CustomizeCell(ByVal e As CustomizePivotCellEventArgs)
    If e.ExportArea = PivotExportArea.Column AndAlso e.ValueItemInfo.Field IsNot Nothing AndAlso e.Value Is Nothing AndAlso e.ValueItemInfo.Value IsNot Nothing Then
        e.Value = e.ValueItemInfo.Field.GetValueText(e.ValueItemInfo.Value)
        e.Handled = True
    End If
End Sub

See Also

MergeRowFieldValues

PivotGridOptionsPrint Class

PivotGridOptionsPrint Members

DevExpress.XtraPivotGrid Namespace