+my $default_format = $workbook->add_format(locked => 0);
+
+my %money_format;
+my $money_char = FS::Conf->new->config('money_char') || '$';
+
+my $writer = sub {
+ # Wrapper for $worksheet->write.
+ # Do any massaging of the value/format here.
+ my ($r, $c, $value, $format) = @_;
+ if ( $value =~ /^\Q$money_char\E(\d+\.?\d*)$/ ) {
+ # Currency: strip the symbol, clone the requested format,
+ # and format it for currency
+ $value = $1;
+ if ( !exists($money_format{$format}) ) {
+ $money_format{$format} = $workbook->add_format();
+ $money_format{$format}->copy($format);
+ $money_format{$format}->set_num_format($money_char.'#0.00#');
+ }
+ $format = $money_format{$format};
+ }
+ $worksheet->write($r, $c, $value, $format);
+};