Back to Devexpress

Print and Export

wpf-401967-controls-and-libraries-gantt-control-print-and-export.md

latest17.5 KB
Original Source

Print and Export

  • Nov 02, 2023
  • 6 minutes to read

Run Demo: WPF Gantt Control - Printing

You can print and export the GanttControl. Use the GanttView.PrintArea property to specify whether to print/export the entire GanttControl, the TreeList area, or the Gantt area.

Built-in Print Preview Window

The Print Preview window allows users to print a document or export it to a PDF/Image file.

To invoke the Print Preview window, call one of the following methods:

MethodDescription
GanttView.ShowPrintPreviewRenders the View in a document and displays it in the Print Preview window.
GanttView.ShowPrintPreviewDialogRenders the View in a document and displays it in the modal Print Preview window.
GanttView.ShowRibbonPrintPreviewRenders the View in a document and displays it in the Print Preview window with the Ribbon UI.
GanttView.ShowRibbonPrintPreviewDialogRenders the View in a document and displays it in the modal Print Preview window with the Ribbon UI.

To print GanttControl data, call one of the following methods:

MethodDescription
GanttView.PrintInvokes the standard Print dialog that allows users to print the GanttControl.
GanttView.PrintDirectUses the default printer to print the GanttControl.

Export Data in Code

You can use the following methods to export GanttControl data in code:

|

Format

|

Method

|

Export Area

|

Export Mode

| | --- | --- | --- | --- | |

PDF

|

GanttView.ExportToPDF

|

Entire Control / TreeList Area / Gantt Area

|

WYSIWYG

| |

Image

|

GanttView.ExportToImage

|

Entire Control / TreeList Area / Gantt Area

|

WYSIWYG

| |

XLS

|

GanttView.ExportToXls

|

TreeList Area

|

Data-Aware

| |

XLSX

|

GanttView.ExportToXlsx

|

TreeList Area

|

Data-Aware

| |

CSV

|

GanttView.ExportToCsv

|

TreeList Area

|

Data-Aware

| |

XPS

|

GanttView.ExportToXps

|

TreeList Area

|

WYSIWYG

| |

TXT

|

GanttView.ExportToText

|

TreeList Area

|

WYSIWYG

| |

DOCX

|

GanttView.ExportToDocx

|

TreeList Area

|

WYSIWYG

| |

RTF

|

GanttView.ExportToRtf

|

TreeList Area

|

WYSIWYG

| |

HTML

|

GanttView.ExportToHtml

|

TreeList Area

|

WYSIWYG

| |

MHT

|

GanttView.ExportToMht

|

TreeList Area

|

WYSIWYG

|

WYSIWYG Export

WYSIWYG Export methods use the Printing-Exporting library to export data. An exported document retains the layout and appearance of Gantt elements. The following formats are supported:

  • PDF - the entire GanttControl or its areas (TreeList / Tasks and Timeline).
  • Image (BMP, EMF, WMF, GIF, JPEG, PNG, TIFF) - the entire GanttControl or its areas (TreeList / Tasks and Timeline).
  • XPS , TXT , DOCX , RTF , HTML , MHT - TreeList only.

xaml
<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView PrintArea="EntireControl"
                        PrintDateRange="(10/5/2020)-(10/18/2020)"
                        x:Name="ganttView"/>
    </dxgn:GanttControl.View>
</dxgn:GanttControl>
csharp
void ExportData(object sender, System.Windows.RoutedEventArgs e) {
    ganttView.ExportToPdf(@"c:\Examples\gantt_export.pdf");
}
vb
Private Sub ExportData(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
    ganttView.ExportToPdf("c:\Examples\gantt_export.pdf")
End Sub

Data-Aware Export

Data-Aware export methods allow users to process exported data in Microsoft Excel. The GanttControl ignores the GanttView.PrintArea property value and exports its TreeList area only.

csharp
void ExportData(object sender, System.Windows.RoutedEventArgs e){
    ganttView.ExportToXlsx(@"c:\Examples\gantt_export.xlsx");
}
vb
Private Sub ExportData(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
    ganttView.ExportToXlsx("c:\Examples\gantt_export.xlsx")
End Sub

Printing Options

PropertyDescription
GanttView.PrintAreaSpecifies whether to print the entire Gantt Area, the tree of tasks and subtasks, or the chart.
GanttView.PrintDateRangeSpecifies the date range for which to print tasks. Connectors for tasks outside the specified range are not printed.
GanttView.PrintGanttAreaScrollMarginSpecifies the outer indents of the Gantt task area.
GanttView.PrintHeadersOnFirstPageOnlySpecifies whether to print column headers only on the first page. If the GanttView.PrintArea is set to TreeList , column headers are printed on each page regardless of the PrintHeadersOnFirstPageOnly property value.

Show TreeList Area Properties

PropertyDescription
GanttView.PrintAutoWidthSpecifies whether to change the TreeList area’s width to fit the page.
GanttView.PrintBandHeadersSpecifies whether to print band headers.
GanttView.PrintColumnHeadersSpecifies whether to print column headers.
GanttView.PrintExpandButtonsSpecifies whether to print expand buttons.
GanttView.PrintNodeImagesSpecifies whether to print node images.
GanttView.AllowPrintColumnHeaderImageSpecifies whether to print column header images.
GanttView.PrintRootIndentSpecifies whether to print expand buttons.
GanttView.PrintRowIndentWidthSpecifies whether to print an indent for the root node.
GanttView.PrintSelectedRowsOnlySpecifies whether to print only the selected rows.
GanttView.PrintTotalSummarySpecifies whether to print the Summary Panel.
GanttView.PrintFixedTotalSummarySpecifies whether to print the Fixed Summary Panel.
GanttView.PrintAllNodesSpecifies whether to expand all nodes in the printed document.
GanttColumn.AllowPrintingSpecifies whether to display the column in the printed/exported document.

Customize Appearance

The printed GanttControl ignores regular Style and Template properties. The GanttControl‘s View has special Styles and Templates that define the printed document’s appearance.

PropertyDescription
GanttView.PrintTaskStyleSpecifies the style applied to tasks.
GanttView.PrintTaskBaselineStyleSpecifies the style applied to task baselines.
GanttView.PrintSummaryTaskStyleSpecifies the style applied to summary tasks.
GanttView.PrintSummaryTaskBaselineStyleSpecifies the style applied to summary task baselines.
GanttView.PrintMilestoneStyleSpecifies the style applied to milestones.
GanttView.PrintMilestoneBaselineStyleSpecifies the style applied to milestone baselines.
GanttView.PrintConnectorStyleSpecifies the style applied to connectors.
GanttView.PrintResourceStyleSpecifies the style applied to resources.
GanttView.PrintGanttRowStyleSpecifies the style applied to Gantt rows.
GanttView.PrintTimescaleRulerStyleSpecifies the style applied to timescale rulers.
GanttView.PrintMarkedTimeIntervalsStyleSpecifies the style applied to marked time intervals.
StripLineBase.PrintControlStyleSpecifies the style applied to strip lines.
GanttView.PrintTaskContentTemplate, GanttView.PrintTaskContentTemplateSelectorSpecifies the template applied to task contents.

Show TreeList Area Styles and Templates

PropertyDescription
GanttView.PrintBandHeaderStyleSpecifies the style applied to band headers.
GanttView.PrintColumnHeaderStyleSpecifies the style applied to column headers.
GanttView.PrintCellStyleSpecifies the style applied to data cells.
GanttView.PrintRowIndentStyleSpecifies the style applied to row indents.
GanttView.PrintTotalSummaryStyleSpecifies the style applied to the Summary Panel.
GanttView.PrintFixedTotalSummaryStyleSpecifies the style applied to the Fixed Summary Panel.
GanttColumn.PrintCellStyleSpecifies the style applied to the column’s data cells.
GanttColumn.PrintColumnHeaderStyleSpecifies the style applied to the column header.
GanttColumn.PrintTotalSummaryStyleSpecifies the style applied to the column’s total summary.
GanttColumn.ActualPrintTotalSummaryStyleReturns the style applied to the column’s total summary.
GanttColumn.ActualPrintCellStyleReturns the style applied to the column’s data cells.
GanttColumn.ActualPrintColumnHeaderStyleReturns the style applied to the column header.
GanttView.PrintRowTemplateSpecifies the template applied to data rows.
GanttView.PrintHeaderTemplateSpecifies the template applied to column headers.
GanttView.PrintFooterTemplateSpecifies the template applied to the Summary Panel.
GanttView.PrintFixedFooterTemplateSpecifies the template applied to the Fixed Summary Panel.

For information on how to customize the GanttControl‘s TreeList area, refer to the Printing and Exporting topic in documentation for the DevExpress WPF Grid.

Example: Change the Printed GanttControl Appearance

xaml
<Window xmlns:dxgn="http://schemas.devexpress.com/winfx/2008/xaml/gantt"
        xmlns:dxgnn="http://schemas.devexpress.com/winfx/2008/xaml/gantt/internal">
    <Window.Resources>

        <Style x:Key="customPrintTimescaleRulerStyle" TargetType="{x:Type dxgnn:TimescaleRulerControl}">
            <Setter Property="Background" Value="White"/>
        </Style>

        <Style x:Key="customPrintMilestoneStyle" TargetType="{x:Type dxgn:GanttMilestoneControl}">
            <Setter Property="Background" Value="#0173C7"/>
        </Style>

        <Style x:Key="customPrintMilestoneBaselineStyle" TargetType="{x:Type dxgn:GanttMilestoneBaselineControl}">
            <Setter Property="Background" Value="Gray"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Opacity" Value=".5"/>
        </Style>

        <Style x:Key="customPrintTaskBaselineStyle" TargetType="{x:Type dxgn:GanttTaskBaselineControl}">
            <Setter Property="Background" Value="Gray"/>
            <Setter Property="Opacity" Value=".5"/>
        </Style>

        <Style x:Key="customPrintSummaryTaskBaselineStyle" TargetType="{x:Type dxgn:GanttSummaryTaskBaselineControl}">
            <Setter Property="Background" Value="Gray"/>
            <Setter Property="Opacity" Value=".5"/>
        </Style>

    </Window.Resources>
    <dxgn:GanttControl ItemsSource="{Binding Tasks}" ...>
        <dxgn:GanttControl.View>
            <dxgn:GanttView PrintArea="Gantt"
                            PrintDateRange="(9/15/2020)-(9/25/2020)"
                            PrintTimescaleRulerStyle="{StaticResource customPrintTimescaleRulerStyle}"
                            PrintMilestoneStyle="{StaticResource customPrintMilestoneStyle}"
                            PrintMilestoneBaselineStyle="{StaticResource customPrintMilestoneBaselineStyle}"
                            PrintTaskBaselineStyle="{StaticResource customPrintTaskBaselineStyle}"
                            PrintSummaryTaskBaselineStyle="{StaticResource customPrintSummaryTaskBaselineStyle}"/>
        </dxgn:GanttControl.View>
        ...
    </dxgn:GanttControl>
</Window>

See Also

Document Post-Processing