-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintingActions.cs
71 lines (61 loc) · 3.04 KB
/
PrintingActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Drawing;
#region #printingUsings
using DevExpress.Spreadsheet;
using DevExpress.XtraPrinting;
using DevExpress.Xpf.Printing;
using System.Windows.Controls;
#endregion #printingUsings
namespace SpreadsheetControl_WPF_API
{
public static class PrintingActions {
public static Action<IWorkbook> PrintAction = Print;
static void Print(IWorkbook workbook) {
Worksheet worksheet = workbook.Worksheets[0];
// Generate worksheet content - the simple multiplication table.
CellRange columnHeadings = worksheet.Range.FromLTRB(1,0,40,0);
columnHeadings.Formula = "=COLUMN() - 1";
CellRange rowHeadings = worksheet.Range.FromLTRB(0,1,0,40);
rowHeadings.Formula = "=ROW() - 1";
CellRange tableRange = worksheet.Range.FromLTRB(1,1,40,40);
tableRange.Formula = "=(ROW()-1)*(COLUMN()-1)";
// Format headers of the multiplication table.
Formatting rangeFormatting = columnHeadings.BeginUpdateFormatting();
rangeFormatting.Borders.BottomBorder.LineStyle = BorderLineStyle.Thin;
rangeFormatting.Borders.BottomBorder.Color = Color.Black;
columnHeadings.EndUpdateFormatting(rangeFormatting);
rangeFormatting = rowHeadings.BeginUpdateFormatting();
rangeFormatting.Borders.RightBorder.LineStyle = BorderLineStyle.Thin;
rangeFormatting.Borders.RightBorder.Color = Color.Black;
rowHeadings.EndUpdateFormatting(rangeFormatting);
rangeFormatting = tableRange.BeginUpdateFormatting();
rangeFormatting.Fill.BackgroundColor = Color.LightBlue;
tableRange.EndUpdateFormatting(rangeFormatting);
#region #WorksheetPrintOptions
worksheet.ActiveView.Orientation = PageOrientation.Landscape;
// Display row and column headings.
worksheet.ActiveView.ShowHeadings = true;
worksheet.ActiveView.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A4;
// Access an object that contains print options.
WorksheetPrintOptions printOptions = worksheet.PrintOptions;
// Print in black and white.
printOptions.BlackAndWhite = true;
// Do not print gridlines.
printOptions.PrintGridlines = false;
// Scale the print area to fit to two pages wide.
printOptions.FitToPage = true;
printOptions.FitToWidth = 2;
// Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash;
#endregion #WorksheetPrintOptions
#region #PrintWorkbook
// Invoke the Print Preview dialog for the workbook.
using (LegacyPrintableComponentLink link = new LegacyPrintableComponentLink(workbook))
{
link.CreateDocument();
link.ShowPrintPreviewDialog(App.Current.MainWindow);
}
#endregion #PrintWorkbook
}
}
}