wpf-401967-controls-and-libraries-gantt-control-print-and-export.md
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.
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:
| Method | Description |
|---|---|
| GanttView.ShowPrintPreview | Renders the View in a document and displays it in the Print Preview window. |
| GanttView.ShowPrintPreviewDialog | Renders the View in a document and displays it in the modal Print Preview window. |
| GanttView.ShowRibbonPrintPreview | Renders the View in a document and displays it in the Print Preview window with the Ribbon UI. |
| GanttView.ShowRibbonPrintPreviewDialog | Renders 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:
| Method | Description |
|---|---|
| GanttView.Print | Invokes the standard Print dialog that allows users to print the GanttControl. |
| GanttView.PrintDirect | Uses the default printer to print the GanttControl. |
You can use the following methods to export GanttControl data in code:
|
Format
|
Method
|
Export Area
|
Export Mode
| | --- | --- | --- | --- | |
|
|
Entire Control / TreeList Area / Gantt Area
|
WYSIWYG
| |
Image
|
|
Entire Control / TreeList Area / Gantt Area
|
WYSIWYG
| |
XLS
|
|
TreeList Area
|
Data-Aware
| |
XLSX
|
|
TreeList Area
|
Data-Aware
| |
CSV
|
|
TreeList Area
|
Data-Aware
| |
XPS
|
|
TreeList Area
|
WYSIWYG
| |
TXT
|
|
TreeList Area
|
WYSIWYG
| |
DOCX
|
|
TreeList Area
|
WYSIWYG
| |
RTF
|
|
TreeList Area
|
WYSIWYG
| |
HTML
|
|
TreeList Area
|
WYSIWYG
| |
MHT
|
|
TreeList Area
|
WYSIWYG
|
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:
<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>
void ExportData(object sender, System.Windows.RoutedEventArgs e) {
ganttView.ExportToPdf(@"c:\Examples\gantt_export.pdf");
}
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 methods allow users to process exported data in Microsoft Excel. The GanttControl ignores the GanttView.PrintArea property value and exports its TreeList area only.
void ExportData(object sender, System.Windows.RoutedEventArgs e){
ganttView.ExportToXlsx(@"c:\Examples\gantt_export.xlsx");
}
Private Sub ExportData(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
ganttView.ExportToXlsx("c:\Examples\gantt_export.xlsx")
End Sub
| Property | Description |
|---|---|
| GanttView.PrintArea | Specifies whether to print the entire Gantt Area, the tree of tasks and subtasks, or the chart. |
| GanttView.PrintDateRange | Specifies the date range for which to print tasks. Connectors for tasks outside the specified range are not printed. |
| GanttView.PrintGanttAreaScrollMargin | Specifies the outer indents of the Gantt task area. |
| GanttView.PrintHeadersOnFirstPageOnly | Specifies 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
| Property | Description |
|---|---|
| GanttView.PrintAutoWidth | Specifies whether to change the TreeList area’s width to fit the page. |
| GanttView.PrintBandHeaders | Specifies whether to print band headers. |
| GanttView.PrintColumnHeaders | Specifies whether to print column headers. |
| GanttView.PrintExpandButtons | Specifies whether to print expand buttons. |
| GanttView.PrintNodeImages | Specifies whether to print node images. |
| GanttView.AllowPrintColumnHeaderImage | Specifies whether to print column header images. |
| GanttView.PrintRootIndent | Specifies whether to print expand buttons. |
| GanttView.PrintRowIndentWidth | Specifies whether to print an indent for the root node. |
| GanttView.PrintSelectedRowsOnly | Specifies whether to print only the selected rows. |
| GanttView.PrintTotalSummary | Specifies whether to print the Summary Panel. |
| GanttView.PrintFixedTotalSummary | Specifies whether to print the Fixed Summary Panel. |
| GanttView.PrintAllNodes | Specifies whether to expand all nodes in the printed document. |
| GanttColumn.AllowPrinting | Specifies whether to display the column in the printed/exported document. |
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.
| Property | Description |
|---|---|
| GanttView.PrintTaskStyle | Specifies the style applied to tasks. |
| GanttView.PrintTaskBaselineStyle | Specifies the style applied to task baselines. |
| GanttView.PrintSummaryTaskStyle | Specifies the style applied to summary tasks. |
| GanttView.PrintSummaryTaskBaselineStyle | Specifies the style applied to summary task baselines. |
| GanttView.PrintMilestoneStyle | Specifies the style applied to milestones. |
| GanttView.PrintMilestoneBaselineStyle | Specifies the style applied to milestone baselines. |
| GanttView.PrintConnectorStyle | Specifies the style applied to connectors. |
| GanttView.PrintResourceStyle | Specifies the style applied to resources. |
| GanttView.PrintGanttRowStyle | Specifies the style applied to Gantt rows. |
| GanttView.PrintTimescaleRulerStyle | Specifies the style applied to timescale rulers. |
| GanttView.PrintMarkedTimeIntervalsStyle | Specifies the style applied to marked time intervals. |
| StripLineBase.PrintControlStyle | Specifies the style applied to strip lines. |
| GanttView.PrintTaskContentTemplate, GanttView.PrintTaskContentTemplateSelector | Specifies the template applied to task contents. |
Show TreeList Area Styles and Templates
| Property | Description |
|---|---|
| GanttView.PrintBandHeaderStyle | Specifies the style applied to band headers. |
| GanttView.PrintColumnHeaderStyle | Specifies the style applied to column headers. |
| GanttView.PrintCellStyle | Specifies the style applied to data cells. |
| GanttView.PrintRowIndentStyle | Specifies the style applied to row indents. |
| GanttView.PrintTotalSummaryStyle | Specifies the style applied to the Summary Panel. |
| GanttView.PrintFixedTotalSummaryStyle | Specifies the style applied to the Fixed Summary Panel. |
| GanttColumn.PrintCellStyle | Specifies the style applied to the column’s data cells. |
| GanttColumn.PrintColumnHeaderStyle | Specifies the style applied to the column header. |
| GanttColumn.PrintTotalSummaryStyle | Specifies the style applied to the column’s total summary. |
| GanttColumn.ActualPrintTotalSummaryStyle | Returns the style applied to the column’s total summary. |
| GanttColumn.ActualPrintCellStyle | Returns the style applied to the column’s data cells. |
| GanttColumn.ActualPrintColumnHeaderStyle | Returns the style applied to the column header. |
| GanttView.PrintRowTemplate | Specifies the template applied to data rows. |
| GanttView.PrintHeaderTemplate | Specifies the template applied to column headers. |
| GanttView.PrintFooterTemplate | Specifies the template applied to the Summary Panel. |
| GanttView.PrintFixedFooterTemplate | Specifies 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.
<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