sbPrinter Example Code
dim r As new sbPrinter(5,5,5,0)
r.PageOrientation = "P"
dim f As sbFont = CreateBaseFont
f.TextFont = "Verdana"
f.TextSize = 18
f.TextColor = colBlueberry ' I have a graphics module that has all colours in constants
dim b As sbBox
' Header
r.ColumnPercentages = "100"
r.SetFont(f)
r.AddHeaderRow
r.CellText(r.LastIndex, 0) = "All Unlinked Transactions"
r.CellAlignment(r.LastIndex, 0) = "C"
b.Top = True
b.Bottom = True
b.Left = True
b.Right = True
r.CellBox(r.LastIndex, 0) = b
' Footer
f.TextFont = "Gill Sans"
f.TextSize = 8
f.TextColor = colAluminium ' I have a graphics module that has all colours in constants
r.ColumnPercentages = "35,35,30"
r.SetFont(f)
r.AddFooterRow
r.CellText(r.LastIndex, 0) = "Unlinked Transactions"
r.CellText(r.LastIndex, 1) = "© Simon Berridge, 2015"
r.CellText(r.LastIndex, 2) = "Page %p."
r.CellAlignment(r.LastIndex, 1) = "C"
r.CellAlignment(r.LastIndex, 2) = "R"
b.Top = True
b.Bottom = False
b.Left = False
b.Right = False
for lp as integer = 0 to 2
r.CellBox(r.LastIndex, lp) = b
next
' Do table heading
' Account,Date,Type,Payee,Amount
r.ColumnPercentages = "18,12,14,44,12"
r.AddTableHeader
f.TextFont = "Gill Sans"
f.TextSize = 12
f.TextColor = colBlueberry
r.SetFont(f)
r.AddRow
r.CellText(r.LastIndex, 0) = "Account"
r.CellText(r.LastIndex, 1) = "Date"
r.CellText(r.LastIndex, 2) = "Type"
r.CellText(r.LastIndex, 3) = "Payee"
r.CellText(r.LastIndex, 4) = "Amount"
for lp1 as integer = 0 to 4
r.CellBackColor(r.LastIndex, lp1) = colBanana
next
r.CellAlignment(r.LastIndex, 1) = "c"
r.CellAlignment(r.LastIndex, 2) = "c"
r.CellAlignment(r.LastIndex, 4) = "r"
r.StopTableHeader
' Table
f.TextFont = "Gill Sans"
f.TextSize = 10
f.TextColor = colBlack ' Graphics module with all colours in constants
r.SetFont(f)
' I use the SQLPlugin from MBS.
' You will use this or the standard Xojo components
dim s As new SQLCommandMBS(DB, "Select Trans.mKey, Trans.AcctID, Trans.TrnType, Trans.DtPosted, Trans.Payee, Trans.TrnAmt From Trans Where Trans.BudAcct = 0 Order By Trans.Payee, Trans.DtPosted")
s.Execute
if s.isResultSet then
while s.FetchNext
r.AddRow
r.CellText(r.LastIndex, 0) = s.Field("AcctID").asStringValue
dim dt As new Date(s.Field("DtPosted").asDate)
r.CellText(r.LastIndex, 1) = dt.FormattedDate("dd-mmm-yyyy")
r.CellText(r.LastIndex, 2) = s.Field("TrnType").asStringValue
r.CellText(r.LastIndex, 3) = s.Field("Payee").asStringValue
r.CellText(r.LastIndex, 4) = Format(s.Field("TrnAmt").asDouble, CurrencyFormatString)
if s.Field("TrnAmt").asDouble < 0 then
r.CellTextColor(r.LastIndex, 4) = colMaraschino ' Graphics module with all colours in constants
else
r.CellTextColor(r.LastIndex, 4) = colFern ' Graphics module with all colours in constants
end if
r.CellAlignment(r.LastIndex, 1) = "c"
r.CellAlignment(r.LastIndex, 2) = "c"
r.CellAlignment(r.LastIndex, 4) = "r"
wend
end if
r.EndTableHeader
r.Print mPrinterSetup
Copyright © Simon Berridge. All Rights Reserved.