+sub output_row{
+ my ($data,$row,$ws,$wb,$formats,$options) = @_;
+ my @columns = ('A'..'Z','AA'..'ZZ');
+ for my $i (0..$#{$data}) {
+ my $format;
+ if ($options->{auto_format}) {
+ if (looks_like_number($data->[$i])) {
+ my $format_string;
+ # use scientific format?
+ if ($data->[$i] != 0 && (abs($data->[$i]) > 9999 ||
+ abs($data->[$i]) < 0.001)) {
+ $format_string = $options->{sci_format};
+ } else {
+ $format_string = '0';
+ my $digits = length(floor(abs($data->[$i])));
+ if ($options->{max_digits} - $digits > 0 and
+ abs($data->[$i]) != abs(floor($data->[$i]))) {
+ # if there are digits left over, use them for
+ # decimal places, but don't require them
+ $format_string = $format_string.'.'.('#'x($options->{max_digits} - $digits))
+ }
+ }
+ if (not exists $formats->{$format_string}) {
+ $formats->{$format_string} =
+ $wb->add_format();
+ $formats->{$format_string}->
+ set_num_format($format_string);
+ }
+ $format = $formats->{$format_string};
+ }
+ }
+ $ws->write($columns[$i].$row,$data->[$i],defined $format?$format:())
+ }
+}
+