Debian Codegraph @

README

raw
1 NAME
2 Spreadsheet::Wright - simple spreadsheet worker
3
4 SYNOPSIS
5 # EXCEL spreadsheet
6
7 use Spreadsheet::Wright;
8
9 my $s = Spreadsheet::Wright->new(
10 file => 'spreadsheet.xls',
11 format => 'xls',
12 sheet => 'Products',
13 styles => {
14 money => '($#,##0_);($#,##0)',
15 },
16 );
17
18 $s->addrow('foo',{
19 content => 'bar',
20 type => 'number',
21 style => 'money',
22 font_weight => 'bold',
23 font_color => 42,
24 font_face => 'Times New Roman',
25 font_size => 20,
26 align => 'center',
27 valign => 'vcenter',
28 font_decoration => 'strikeout',
29 font_style => 'italic',
30 });
31 $s->addrow('foo2','bar2');
32 $s->freeze(1, 0);
33
34 # CSV file
35
36 use Spreadsheet::Wright;
37
38 my $s = Spreadsheet::Wright->new(
39 file => 'file.csv',
40 encoding => 'iso8859',
41 );
42 die $s->error if $s->error;
43 $s->addrow('foo', 'bar');
44
45 DESCRIPTION
46 `Spreadsheet::Wright` is a fork of Spreadsheet::Write and may be used as a
47 drop-in replacement.
48
49 `Spreadsheet::Wright` writes files in CSV, Microsoft Excel, HTML and
50 OpenDocument formats. It is especially suitable for building various dumps
51 and reports where rows are built in sequence, one after another.
52
53 It is not especially suitable for modifying existing files.
54
55 The name is a not just pun on "write" - the word "wright" means worker or
56 crafter, and `Spreadsheet::Wright` does a lot of the work of spreadsheet
57 output for you!
58
59 Constructor
60 `Spreadsheet::Wright->new(%args)`
61 $spreadsheet = Spreadsheet::Wright->new(
62 file => 'table.xls',
63 styles => {
64 mynumber => '#,##0.00',
65 },
66 );
67
68 Creates a new spreadsheet object. It takes a list of options. The
69 following are valid:
70
71 * file - filename of the new spreadsheet (mandatory)
72
73 * encoding - encoding of output file (optional, csv format only)
74
75 * format - format of spreadsheet - 'csv', 'xls', 'xlsx', 'html',
76 'xhtml', 'xml', 'ods', 'json', or 'auto' (default).
77
78 * sheet - first sheet name (optional, not supported by some formats)
79
80 * styles - defines cell formatting shortcuts (optional)
81
82 * failsafe - boolean - if true, falls back to CSV in emergencies
83
84 If file format is 'auto' (or omitted), the format is guessed from the
85 filename extension, defaulting to 'csv'.
86
87 Methods
88 `addrow($cell_1, $cell_2, ...)`
89 Adds a row into the spreadsheet. Takes arbitrary number of arguments.
90 Arguments represent cell values and may be strings or hash references.
91 If an argument is a hash reference, it takes the following structure:
92
93 content value to put into cell
94 style formatting style, as defined in new()
95 type type of the content (defaults to 'auto')
96 format number format (see Spreadsheet::WriteExcel for details)
97 font_weight weight of font. Only valid value is 'bold'
98 font_style style of font. Only valid value is 'italic'
99 font_decoration 'underline' or 'strikeout' (or both, space separated)
100 font_face font of column; default is 'Arial'
101 font_color color of font (see Spreadsheet::WriteExcel for color values)
102 font_size size of font
103 align alignment
104 valign vertical alignment
105 width column width, excel units (only makes sense once per column)
106 header boolean; is this cell a header?
107
108 Styles can be used to assign default values for any of these
109 formatting parameters thus allowing easy global changes. Other
110 parameters specified override style definitions.
111
112 Example:
113
114 my $sp = Spreadsheet::Wright->new(
115 file => 'employees.xls',
116 styles => {
117 important => { font_weight => 'bold' },
118 },
119 );
120 $sp->addrow(
121 { content => 'First Name', font_weight => 'bold' },
122 { content => 'Last Name', font_weight => 'bold' },
123 { content => 'Age', style => 'important' },
124 );
125 $sp->addrow("John", "Doe", 34);
126 $sp->addrow("Susan", "Smith", 28);
127
128 Note that in this example all header cells will have identical
129 formatting even though some use direct formats and one uses style.
130
131 If you want to store text that looks like a number you might want to
132 use { type => 'string', format => '@' } arguments. By default the type
133 detection is automatic, as done by for instance
134 Spreadsheet::WriteExcel write() method.
135
136 It is also possible to supply an array reference in the 'content'
137 parameter of the extended format. It means to use the same formatting
138 for as many cells as there are elements in this array. Useful for
139 creating header rows. For instance, the above example can be rewritten
140 as:
141
142 $sp->addrow({
143 style => 'important',
144 content => ['First Name', 'Last Name', 'Age'],
145 });
146
147 Not all styling options are supported in all formats.
148
149 `addrows(\@row_1, \@row_2, ...)`
150 Shortcut for adding multiple rows.
151
152 Each argument is an arrayref representing a row.
153
154 Any argument that is not a reference (i.e. a scalar) is taken to be
155 the title of a new worksheet.
156
157 `addsheet($name)`
158 Adds a new sheet into the document and makes it active. Subsequent
159 addrow() calls will add rows to that new sheet.
160
161 For CSV format this call is NOT ignored, but produces a fatal error
162 currently.
163
164 `freeze($row, $col, $top_row, $left_col)`
165 Sets a freeze-pane at the given position, equivalent to
166 Spreadsheet::WriteExcel->freeze_panes(). Only implemented for Excel
167 spreadsheets so far.
168
169 `close`
170 Saves the spreadsheet to disk (some of the modules save incrementally
171 anyway) and closes the file. Calling this explicitly is usually
172 un-necessary, as the Perl garbage collector will do the job eventually
173 anyway. Once a spreadsheet is closed, calls to addrow() will fail.
174
175 `error`
176 Returns the latest recoverable error.
177
178 BUGS
179 Please report any bugs to <http://rt.cpan.org/>.
180
181 SEE ALSO
182 Spreadsheet::Write.
183
184 AUTHORS
185 Toby Inkster <[email protected]>.
186
187 Excel and CSV output based almost entirely on work by Nick Eremeev
188 <[email protected]> <http://ejelta.com/>.
189
190 XLSX output based on work by Andrew Maltsev (AMALTSEV).
191
192 COPYRIGHT AND LICENCE
193 Copyright 2007 Nick Eremeev.
194
195 Copyright 2010-2011 Toby Inkster.
196
197 This library is free software; you can redistribute it and/or modify it
198 under the same terms as Perl itself.
199
200 DISCLAIMER OF WARRANTIES
201 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
202 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
203 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
204