-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPrintingActions.cs
71 lines (59 loc) · 2.99 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;
#endregion #printingUsings
namespace SpreadsheetExamples {
public static class PrintingActions {
public static Action<Workbook> PrintAction = Print;
static void Print(Workbook workbook) {
Worksheet worksheet = workbook.Worksheets[0];
// Generate a simple multiplication table.
CellRange topHeader = worksheet.Range.FromLTRB(1, 0, 20, 0);
topHeader.Formula = "=COLUMN() - 1";
CellRange leftCaption = worksheet.Range.FromLTRB(0, 1, 0, 20);
leftCaption.Formula = "=ROW() - 1";
CellRange tableRange = worksheet.Range.FromLTRB(1, 1, 20, 20);
tableRange.Formula = "=(ROW()-1)*(COLUMN()-1)";
// Format headers of the multiplication table.
Formatting rangeFormatting = topHeader.BeginUpdateFormatting();
rangeFormatting.Borders.BottomBorder.LineStyle = BorderLineStyle.Thin;
rangeFormatting.Borders.BottomBorder.Color = Color.Black;
topHeader.EndUpdateFormatting(rangeFormatting);
rangeFormatting = leftCaption.BeginUpdateFormatting();
rangeFormatting.Borders.RightBorder.LineStyle = BorderLineStyle.Thin;
rangeFormatting.Borders.RightBorder.Color = Color.Black;
leftCaption.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 a page.
printOptions.FitToPage = true;
// 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 (PrintingSystem printingSystem = new PrintingSystem()) {
using (PrintableComponentLink link = new PrintableComponentLink(printingSystem)) {
link.Component = workbook;
link.CreateDocument();
link.ShowPreviewDialog();
}
}
#endregion #PrintWorkbook
}
}
}