File: rich_strings.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 (43 lines) | stat: -rw-r--r-- 1,299 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
#!/usr/bin/perl

#######################################################################
#
# An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
# strings with multiple formatting.
#
# reverse ('(c)'), February 2011, John McNamara, jmcnamara@cpan.org
#

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

my $workbook  = Excel::Writer::XLSX->new( 'rich_strings.xlsx' );
my $worksheet = $workbook->add_worksheet();

$worksheet->set_column( 'A:A', 30 );

# Set some formats to use.
my $bold   = $workbook->add_format( bold        => 1 );
my $italic = $workbook->add_format( italic      => 1 );
my $red    = $workbook->add_format( color       => 'red' );
my $blue   = $workbook->add_format( color       => 'blue' );
my $center = $workbook->add_format( align       => 'center' );
my $super  = $workbook->add_format( font_script => 1 );


# Write some strings with multiple formats.
$worksheet->write_rich_string( 'A1',
    'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );

$worksheet->write_rich_string( 'A3',
    'This is ', $red, 'red', ' and this is ', $blue, 'blue' );

$worksheet->write_rich_string( 'A5',
    'Some ', $bold, 'bold text', ' centered', $center );

$worksheet->write_rich_string( 'A7',
    $italic, 'j = k', $super, '(n-1)', $center );


__END__