my $child_success = $self->iterate_over_children($context);
$context->active_format($old_format);
+
+ return $child_success;
}
1;
=over 4
+Boolean attributes should be set to 1, 0, true, or false.
+
+Color values can be the color name or the color index. See http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.11/lib/Spreadsheet/WriteExcel.pm#COLOURS_IN_EXCEL
+
+
+=item * align
+
+Set to either left, center, right, fill, or justify. Default is left. See also valign.
+
+=item * bg_color
+
+Set to a color value. Default is none.
+
=item * bold
This will set bold to on or off, depending on the boolean value.
-=item * hidden
+=item * border
-This will set whether the cell is hidden to on or off, depending on the boolean
-value. (q.v. BOLD tag)
+Set the border for all for edges of a cell. Also see bottom, top, left, and right.
+Valid values are 0 - 7.
-=item * italic
+http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.11/lib/Spreadsheet/WriteExcel.pm#set_border()
-This will set italic to on or off, depending on the boolean value. (q.v. ITALIC
-tag)
+=item * border_color
+
+Sets the color value for the border. See also border, top_color, bottom_color, left_color
+and right_color.
+
+=item * bottom
+
+See border.
+
+=item * bottom_color
+
+See border_color
+
+=item * color
+
+This will set the color of the text, depending on color value. Default is black.
+
+=item * fg_color
+
+Set to a color value. This color will be used in foreground of some patterns. See color
+to change the color of text. Also see bg_color and pattern.
+
+=item * font
+
+This will sent the font face. Default is Arial.
=item * font_outline
=item * font_shadow
This will set font_shadow to on or off, depending on the boolean value. (q.v.
-SHADOW tag)
+SHADOW tag). This only applies to Excel for Macintosh.
=item * font_strikeout
This will set font_strikeout to on or off, depending on the boolean value. (q.v.
STRIKEOUT tag)
+=item * hidden
+
+This will set whether the cell is hidden to on or off, depending on the boolean
+value.
+
+=item * indent
+
+Set the indentation level for a cell. Positive integers are allowed.
+
+=item * italic
+
+This will set italic to on or off, depending on the boolean value. (q.v. ITALIC
+tag)
+
+=item * left
+
+See border.
+
+=item * left_color
+
+See border_color.
+
+=item * num_format
+
+Set to the index of one of Excel's built-in number formats. See http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.11/lib/Spreadsheet/WriteExcel.pm#set_num_format()
+
+=item * pattern
+
+Set to an integer, 0 - 18. Sets the background fill pattern of a ell. Default is 1, solid.
+
+=item * right
+
+See border.
+
+=item * right_color
+
+See border color.
+
+=item * rotation
+
+Set the rotation of the text in a cell. The rotation can be any angle in the range -90 to 90 degrees.
+The angle 270 is also supported. This indicates text where the letters run from top to bottom.
+
+=item * shrink
+
+A boolean value. If true, text will shrink to fit a cell.
+
+=item * size
+
+This will set the size of the font. Default is 10. Unless a row height is
+specifically set, the row will grow taller as necessary.
+
+=item * text_justlast
+
+A boolean value to justify the last line. Only applies to Far Eastern versions of Excel.
+
+=item * text_wrap
+
+A boolean value. When set to true, text will wrap in a cell instead of crossing over
+into empty cells. If the row height is not set, the row will grow taller to accomodate
+the wrapping text.
+
+=item * top
+
+See border.
+
+=item * top_color
+
+See border_color
+
+=item * valign
+
+Set to top, vcenter, bottom, or vjustify. Default is vcenter. See also align.
+
=back 4
=head1 CHILDREN
=head1 AUTHOR
-Rob Kinyon (rkinyon@columbus.rr.com)
+Rob Kinyon (rob.kinyon@gmail.com)
=head1 SEE ALSO
# formats and making new formats based on old ones.
{
- # %_Parameters is a hash with the key being the format name and the value
- # being the index/length of the format in the bit-vector.
- my %_Formats = (
- bold => [ 0, 1 ],
- italic => [ 1, 1 ],
- locked => [ 2, 1 ],
- hidden => [ 3, 1 ],
- font_outline => [ 4, 1 ],
- font_shadow => [ 5, 1 ],
- font_strikeout => [ 6, 1 ],
+ my %_Formats;
+
+ sub _assign { $_Formats{$_[0]} = $_[1]; $_Formats{$_[1]} = $_[0] }
+# my $key = shift;
+# my $format = shift;
+# $_Formats{$key} = $format;
+# $_Formats{$format} = $key;
+# }
+
+ sub _retrieve_key { $_Formats{ $_[0] } }
+# my $format = shift;
+# return $_Formats{$format};
+# }
+
+ *_retrieve_format = \&_retrieve_key;
+# sub _retrieve_format {
+# my $key = shift;
+# return $_Formats{$key};
+# }
+}
+
+{
+ my @_boolean_formats = qw(
+ bold italic locked hidden font_outline font_shadow font_strikeout
+ text_wrap text_justlast shrink
);
-
- sub _params_to_vec
+
+ my @_integer_formats = qw(
+ size num_format underline rotation indent pattern border
+ bottom top left right
+ );
+
+ my @_string_formats = qw(
+ font color align valign bg_color fg_color border_color
+ bottom_color top_color left_color right_color
+ );
+
+ sub _params_to_key
{
my %params = @_;
$params{lc $_} = delete $params{$_} for keys %params;
-
- my $vec = '';
- vec( $vec, $_Formats{$_}[0], $_Formats{$_}[1] ) = ($params{$_} && 1)
- for grep { exists $_Formats{$_} }
- map { lc } keys %params;
-
- $vec;
+
+ my @parts = (
+ (map { !! $params{$_} } @_boolean_formats),
+ (map { $params{$_} ? $params{$_} + 0 : '' } @_integer_formats),
+ (map { $params{$_} || '' } @_string_formats),
+ );
+
+ return join( "\n", @parts );
}
-
- sub _vec_to_params
+
+ sub _key_to_params
{
- my ($vec) = @_;
-
+ my ($key) = @_;
+
+ my @key_parts = split /\n/, $key;
+
+ my @boolean_parts = splice @key_parts, 0, scalar( @_boolean_formats );
+ my @integer_parts = splice @key_parts, 0, scalar( @_integer_formats );
+ my @string_parts = splice @key_parts, 0, scalar( @_string_formats );
+
my %params;
- while (my ($k, $v) = each %_Formats)
- {
- next unless vec( $vec, $v->[0], $v->[1] );
- $params{$k} = 1;
- }
-
- %params;
- }
-}
+ $params{ $_boolean_formats[$_] } = !!1
+ for grep { $boolean_parts[$_] } 0 .. $#_boolean_formats;
-{
- my %_Formats;
+ $params{ $_integer_formats[$_] } = $integer_parts[$_]
+ for grep { length $integer_parts[$_] } 0 .. $#_integer_formats;
+
+ $params{ $_string_formats[$_] } = $string_parts[$_]
+ for grep { $string_parts[$_] } 0 .. $#_string_formats;
- sub _assign {
- $_Formats{$_[0]} = $_[1] unless exists $_Formats{$_[0]};
- $_Formats{$_[1]} = $_[0] unless exists $_Formats{$_[1]};
+ return %params;
}
- sub _retrieve_vec { ref($_[0]) ? ($_Formats{$_[0]}) : ($_[0]); }
- sub _retrieve_format { ref($_[0]) ? ($_[0]) : ($_Formats{$_[0]}); }
-}
+ sub copy
+ {
+ shift;
+ my ($context, $old_fmt, %properties) = @_;
-sub blank_format
-{
- shift;
- my ($context) = @_;
+ defined(my $key = _retrieve_key($old_fmt))
+ || die "Internal Error: Cannot find key for format '$old_fmt'!\n";
+
+ my %params = _key_to_params($key);
+ PROPERTY:
+ while ( my ($prop, $value) = each %properties )
+ {
+ $prop = lc $prop;
+ foreach (@_boolean_formats)
+ {
+ if ($prop eq $_) {
+ $params{$_} = ($value && $value !~ /false/i);
+ next PROPERTY;
+ }
+ }
+ foreach (@_integer_formats, @_string_formats)
+ {
+ if ($prop eq $_) {
+ $params{$_} = $value;
+ next PROPERTY;
+ }
+ }
+ }
- my $blank_vec = _params_to_vec();
+ my $new_key = _params_to_key(%params);
- my $format = _retrieve_format($blank_vec);
- return $format if $format;
+ my $format = _retrieve_format($new_key);
+ return $format if $format;
- $format = $context->{XLS}->add_format;
- _assign($blank_vec, $format);
- $format;
+ $format = $context->{XLS}->add_format(%params);
+ _assign($new_key, $format);
+ return $format;
+ }
}
-sub copy
+sub blank_format
{
shift;
- my ($context, $old_format, %properties) = @_;
-
- defined(my $vec = _retrieve_vec($old_format))
- || die "Internal Error: Cannot find vector for format '$old_format'!\n";
-
- my $new_vec = _params_to_vec(%properties);
+ my ($context) = @_;
- $new_vec |= $vec;
+ my $blank_key = _params_to_key();
- my $format = _retrieve_format($new_vec);
+ my $format = _retrieve_format($blank_key);
return $format if $format;
- $format = $context->{XLS}->add_format(_vec_to_params($new_vec));
- _assign($new_vec, $format);
- $format;
+ $format = $context->{XLS}->add_format;
+ _assign($blank_key, $format);
+ return $format;
}
1;
__END__
-
-Category Description Property Method Name Implemented
--------- ----------- -------- ----------- -----------
-Font Font type font set_font()
- Font size size set_size()
- Font color color set_color()
- Bold bold set_bold() YES
- Italic italic set_italic() YES
- Underline underline set_underline()
- Strikeout font_strikeout set_font_strikeout() YES
- Super/Subscript font_script set_font_script()
- Outline font_outline set_font_outline() YES
- Shadow font_shadow set_font_shadow() YES
-
-Number Numeric format num_format set_num_format()
-
-Protection Lock cells locked set_locked() YES
- Hide formulas hidden set_hidden() YES
-
-Alignment Horizontal align align set_align()
- Vertical align valign set_align()
- Rotation rotation set_rotation()
- Text wrap text_wrap set_text_wrap()
- Justify last text_justlast set_text_justlast()
- Merge merge set_merge()
-
-Pattern Cell pattern pattern set_pattern()
- Background color bg_color set_bg_color()
- Foreground color fg_color set_fg_color()
-
-Border Cell border border set_border()
- Bottom border bottom set_bottom()
- Top border top set_top()
- Left border left set_left()
- Right border right set_right()
- Border color border_color set_border_color()
- Bottom color bottom_color set_bottom_color()
- Top color top_color set_top_color()
- Left color left_color set_left_color()
- Right color right_color set_right_color()