-
Notifications
You must be signed in to change notification settings - Fork 5
/
PrintingActions.vb
63 lines (59 loc) · 2.99 KB
/
PrintingActions.vb
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
Imports System
Imports System.Drawing
#Region "#printingUsings"
Imports DevExpress.Spreadsheet
Imports DevExpress.XtraPrinting
#End Region ' #printingUsings
Namespace SpreadsheetExamples
Public Module PrintingActions
Public PrintAction As Action(Of Workbook) = AddressOf Print
Private Sub Print(ByVal workbook As Workbook)
Dim worksheet As Worksheet = workbook.Worksheets(0)
' Generate a simple multiplication table.
Dim topHeader As CellRange = worksheet.Range.FromLTRB(1, 0, 20, 0)
topHeader.Formula = "=COLUMN() - 1"
Dim leftCaption As CellRange = worksheet.Range.FromLTRB(0, 1, 0, 20)
leftCaption.Formula = "=ROW() - 1"
Dim tableRange As CellRange = worksheet.Range.FromLTRB(1, 1, 20, 20)
tableRange.Formula = "=(ROW()-1)*(COLUMN()-1)"
' Format headers of the multiplication table.
Dim rangeFormatting As Formatting = 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.
Dim printOptions As WorksheetPrintOptions = 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
#End Region ' #WorksheetPrintOptions
#Region "#PrintWorkbook"
' Invoke the Print Preview dialog for the workbook.
Using printingSystem As PrintingSystem = New PrintingSystem()
Using link As PrintableComponentLink = New PrintableComponentLink(printingSystem)
link.Component = workbook
link.CreateDocument()
link.ShowPreviewDialog()
End Using
End Using
#End Region ' #PrintWorkbook
End Sub
End Module
End Namespace