-
Notifications
You must be signed in to change notification settings - Fork 4
/
headers_footers.bas
117 lines (89 loc) · 4.3 KB
/
headers_footers.bas
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/'
* This program shows several examples of how to set up headers and
* footers with libxlsxwriter.
*
* The control characters used in the header/footer strings are:
*
* Control Category Description
* ======= ======== ===========
* &L Justification Left
* &C Center
* &R Right
* &P Information Page number
* &N Total number of pages
* &D Date
* &T Time
* &F File name
* &A Worksheet name
* &fontsize Font Font size
* &"font,style" Font name and style
* &U Single underline
* &E Double underline
* &S Strikethrough
* &X Superscript
* &Y Subscript
* &[Picture] Images Image placeholder
* &G Same as &[Picture]
* && Miscellaneous Literal ampersand &
*
* Copyright 2014-2017, John McNamara, [email protected]
*
* translated by Lee June by using https://github.com/retsyo/libxlsxwriter_freebasic
'/
#include "auto_xlsxwriter.bi"
function main() as Integer
Dim as lxw_workbook ptr workbook = workbook_new("headers_footers.xlsx")
Dim as String preview = "Select Print Preview to see the header and footer"
/'
* A simple example to start
'/
Dim as lxw_worksheet Ptr worksheet1 = workbook_add_worksheet(workbook, "Simple")
Dim As String header1 = "&CHere is some centered text."
Dim As String footer1 = "&LHere is some left aligned text."
worksheet_set_header(worksheet1, header1)
worksheet_set_footer(worksheet1, footer1)
worksheet_set_column(worksheet1, 0, 0, 50, NULL)
worksheet_write_string(worksheet1, 0, 0, preview, NULL)
/'
* This is an example of some of the header/footer variables.
'/
Dim as lxw_worksheet Ptr worksheet2 = workbook_add_worksheet(workbook, "Variables")
Dim AS String header2 = "&LPage &P of &N" "&CFilename: &F" "&RSheetname: &A"
Dim AS String footer2 = "&LCurrent date: &D" "&RCurrent time: &T"
Dim As lxw_row_t breaks(0 to 1) = {20, 0}
worksheet_set_header(worksheet2, header2)
worksheet_set_footer(worksheet2, footer2)
worksheet_set_column(worksheet2, 0, 0, 50, NULL)
worksheet_write_string(worksheet2, 0, 0, preview, NULL)
' ~ worksheet_set_h_pagebreaks(worksheet2, breaks)
worksheet_write_string(worksheet2, 20, 0, "Next page", NULL)
/'
* This example shows how to use more than one font.
'/
Dim as lxw_worksheet Ptr worksheet3 = workbook_add_worksheet(workbook, "Mixed fonts")
Dim AS String header3 = !"&C&\"Courier New,Bold\"Hello &\"Arial,Italic\"World"
Dim AS String footer3 = !"&C&\"Symbol\"e&\"Arial\" = mc&X2"
worksheet_set_header(worksheet3, header3)
worksheet_set_footer(worksheet3, footer3)
worksheet_set_column(worksheet3, 0, 0, 50, NULL)
worksheet_write_string(worksheet3, 0, 0, preview, NULL)
/'
* Example of line wrapping.
'/
Dim As lxw_worksheet ptr worksheet4 = workbook_add_worksheet(workbook, "Word wrap")
Dim AS String header4 = !"&CHeading 1\nHeading 2"
worksheet_set_header(worksheet4, header4)
worksheet_set_column(worksheet4, 0, 0, 50, NULL)
worksheet_write_string(worksheet4, 0, 0, preview, NULL)
/'
* Example of inserting a literal ampersand &
'/
Dim AS lxw_worksheet ptr worksheet5 = workbook_add_worksheet(workbook, "Ampersand")
Dim AS String header5 = "&CCuriouser && Curiouser - Attorneys at Law"
worksheet_set_header(worksheet5, header5)
worksheet_set_column(worksheet5, 0, 0, 50, NULL)
worksheet_write_string(worksheet5, 0, 0, preview, NULL)
workbook_close(workbook)
return 0
End Function
main()