File: headers.pl

package info (click to toggle)
libexcel-writer-xlsx-perl 0.79-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,716 kB
  • ctags: 930
  • sloc: perl: 18,380; makefile: 40
file content (137 lines) | stat: -rw-r--r-- 4,391 bytes parent folder | download | duplicates (2)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/perl

######################################################################
#
# This program shows several examples of how to set up headers and
# footers with Excel::Writer::XLSX.
#
# 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 &
#
# See the main Excel::Writer::XLSX documentation for more information.
#
# reverse ('(c)'), March 2002, John McNamara, jmcnamara@cpan.org
#


use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( 'headers.xlsx' );
my $preview  = 'Select Print Preview to see the header and footer';


######################################################################
#
# A simple example to start
#
my $worksheet1 = $workbook->add_worksheet( 'Simple' );
my $header1    = '&CHere is some centred text.';
my $footer1    = '&LHere is some left aligned text.';

$worksheet1->set_header( $header1 );
$worksheet1->set_footer( $footer1 );

$worksheet1->set_column( 'A:A', 50 );
$worksheet1->write( 'A1', $preview );


######################################################################
#
# A simple example to start
#
my $worksheet2 = $workbook->add_worksheet( 'Image' );
my $header2    = '&L&[Picture]';

# Adjust the page top margin to allow space for the header image.
$worksheet2->set_margin_top(1.75);

$worksheet2->set_header( $header2, 0.3, {image_left => 'republic.png'});

$worksheet2->set_column( 'A:A', 50 );
$worksheet2->write( 'A1', $preview );


######################################################################
#
# This is an example of some of the header/footer variables.
#
my $worksheet3 = $workbook->add_worksheet( 'Variables' );
my $header3    = '&LPage &P of &N' . '&CFilename: &F' . '&RSheetname: &A';
my $footer3    = '&LCurrent date: &D' . '&RCurrent time: &T';

$worksheet3->set_header( $header3 );
$worksheet3->set_footer( $footer3 );

$worksheet3->set_column( 'A:A', 50 );
$worksheet3->write( 'A1',  $preview );
$worksheet3->write( 'A21', 'Next sheet' );
$worksheet3->set_h_pagebreaks( 20 );


######################################################################
#
# This example shows how to use more than one font
#
my $worksheet4 = $workbook->add_worksheet( 'Mixed fonts' );
my $header4    = q(&C&"Courier New,Bold"Hello &"Arial,Italic"World);
my $footer4    = q(&C&"Symbol"e&"Arial" = mc&X2);

$worksheet4->set_header( $header4 );
$worksheet4->set_footer( $footer4 );

$worksheet4->set_column( 'A:A', 50 );
$worksheet4->write( 'A1', $preview );


######################################################################
#
# Example of line wrapping
#
my $worksheet5 = $workbook->add_worksheet( 'Word wrap' );
my $header5    = "&CHeading 1\nHeading 2";

$worksheet5->set_header( $header5 );

$worksheet5->set_column( 'A:A', 50 );
$worksheet5->write( 'A1', $preview );


######################################################################
#
# Example of inserting a literal ampersand &
#
my $worksheet6 = $workbook->add_worksheet( 'Ampersand' );
my $header6    = '&CCuriouser && Curiouser - Attorneys at Law';

$worksheet6->set_header( $header6 );

$worksheet6->set_column( 'A:A', 50 );
$worksheet6->write( 'A1', $preview );