1 package Excel::Template::Format;
5 # This is the format repository. Spreadsheet::WriteExcel does not cache the
6 # known formats. So, it is very possible to continually add the same format
7 # over and over until you run out of RAM or addressability in the XLS file. In
8 # real life, less than 10-20 formats are used, and they're re-used in various
9 # places in the file. This provides a way of keeping track of already-allocated
10 # formats and making new formats based on old ones.
13 # %_Parameters is a hash with the key being the format name and the value
14 # being the index/length of the format in the bit-vector.
20 font_outline => [ 4, 1 ],
21 font_shadow => [ 5, 1 ],
22 font_strikeout => [ 6, 1 ],
28 $params{lc $_} = delete $params{$_} for keys %params;
31 vec( $vec, $_Formats{$_}[0], $_Formats{$_}[1] ) = ($params{$_} && 1)
32 for grep { exists $_Formats{$_} }
33 map { lc } keys %params;
43 while (my ($k, $v) = each %_Formats)
45 next unless vec( $vec, $v->[0], $v->[1] );
57 $_Formats{$_[0]} = $_[1] unless exists $_Formats{$_[0]};
58 $_Formats{$_[1]} = $_[0] unless exists $_Formats{$_[1]};
61 sub _retrieve_vec { ref($_[0]) ? ($_Formats{$_[0]}) : ($_[0]); }
62 sub _retrieve_format { ref($_[0]) ? ($_[0]) : ($_Formats{$_[0]}); }
70 my $blank_vec = _params_to_vec();
72 my $format = _retrieve_format($blank_vec);
73 return $format if $format;
75 $format = $context->{XLS}->add_format;
76 _assign($blank_vec, $format);
83 my ($context, $old_format, %properties) = @_;
85 defined(my $vec = _retrieve_vec($old_format))
86 || die "Internal Error: Cannot find vector for format '$old_format'!\n";
88 my $new_vec = _params_to_vec(%properties);
92 my $format = _retrieve_format($new_vec);
93 return $format if $format;
95 $format = $context->{XLS}->add_format(_vec_to_params($new_vec));
96 _assign($new_vec, $format);
103 Category Description Property Method Name Implemented
104 -------- ----------- -------- ----------- -----------
105 Font Font type font set_font()
106 Font size size set_size()
107 Font color color set_color()
108 Bold bold set_bold() YES
109 Italic italic set_italic() YES
110 Underline underline set_underline()
111 Strikeout font_strikeout set_font_strikeout() YES
112 Super/Subscript font_script set_font_script()
113 Outline font_outline set_font_outline() YES
114 Shadow font_shadow set_font_shadow() YES
116 Number Numeric format num_format set_num_format()
118 Protection Lock cells locked set_locked() YES
119 Hide formulas hidden set_hidden() YES
121 Alignment Horizontal align align set_align()
122 Vertical align valign set_align()
123 Rotation rotation set_rotation()
124 Text wrap text_wrap set_text_wrap()
125 Justify last text_justlast set_text_justlast()
126 Merge merge set_merge()
128 Pattern Cell pattern pattern set_pattern()
129 Background color bg_color set_bg_color()
130 Foreground color fg_color set_fg_color()
132 Border Cell border border set_border()
133 Bottom border bottom set_bottom()
134 Top border top set_top()
135 Left border left set_left()
136 Right border right set_right()
137 Border color border_color set_border_color()
138 Bottom color bottom_color set_bottom_color()
139 Top color top_color set_top_color()
140 Left color left_color set_left_color()
141 Right color right_color set_right_color()