55 |
|
|
56 |
my $f = $format; |
my $f = $format; |
57 |
|
|
58 |
|
my $eval; |
59 |
|
$eval = $1 if ($f =~ s/^eval{([^}]+?)}//); |
60 |
|
|
61 |
if ($f =~ s/^([^\d]+)//) { |
if ($f =~ s/^([^\d]+)//) { |
62 |
if ($f) { # there is more to parse |
if ($f) { # there is more to parse |
63 |
push @fmt,$1; |
push @fmt,$1; |
114 |
} |
} |
115 |
} |
} |
116 |
push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix |
push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix |
117 |
|
|
118 |
|
$cache->{format_eval}->{$format} = $eval; # store eval string (if any) |
119 |
|
|
120 |
$cache->{format}->{$format} = \@fmt; |
$cache->{format}->{$format} = \@fmt; |
121 |
|
|
122 |
# print STDERR "storing format for '$format': [",join("|",@fmt),"]\n"; |
# print STDERR "storing format for '$format': [",join("|",@fmt),"]\n"; |
157 |
$sufix = shift @fmt; |
$sufix = shift @fmt; |
158 |
} |
} |
159 |
$display = $prefix.$display.$sufix if ($display); |
$display = $prefix.$display.$sufix if ($display); |
|
print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt); |
|
160 |
|
|
161 |
print STDERR "format: [",join("|",@{$tmp}),"]\n" if (@fmt); |
my $eval = $cache->{format_eval}->{$format}; |
162 |
|
if ($eval) { |
163 |
|
sub fld2str { |
164 |
|
my ($func,$row,$f,$sf,$i) = @_; |
165 |
|
#print STDERR "## in fld2str\n"; |
166 |
|
my $tmp = $codepage->convert(&$func($row,$f,$sf,$i)) || $codepage->convert(&$func($row,$f,$sf,0)) || ''; |
167 |
|
return "'$tmp'"; |
168 |
|
} |
169 |
|
|
170 |
|
$eval =~ s/v(\d+)\^(\w*)/fld2str($func,$row,$1,$2,$i)/eg; |
171 |
|
#print STDERR "## eval: $eval\n"; |
172 |
|
if (eval "$eval") { |
173 |
|
die "eval error: eval{$eval}: $@" if ($@); |
174 |
|
return ($swish,$display); |
175 |
|
} else { |
176 |
|
die "eval error: eval{$eval}: $@" if ($@); |
177 |
|
return (undef,undef); |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
|
if (@fmt) { |
182 |
|
print STDERR "format left unused: [",join("|",@fmt),"]\n"; |
183 |
|
print STDERR "format: [",join("|",@{$tmp}),"]\n"; |
184 |
|
} |
185 |
|
|
186 |
# print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n"; |
# print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n"; |
187 |
|
|
194 |
my $format = shift; |
my $format = shift; |
195 |
my $row = shift; |
my $row = shift; |
196 |
my $i = shift; |
my $i = shift; |
197 |
my $codepage = shift; |
#my $codepage = shift; |
198 |
|
# |
199 |
|
# data allready comes in utf-8 due to change in |
200 |
|
# SpreadSheet::ParseExcel::FmtDefault line 69 from |
201 |
|
# return pack('C*', unpack('n*', $sTxt)); |
202 |
|
# to following which returns utf-8: |
203 |
|
# return pack('U*', unpack('n*', $sTxt)); |
204 |
|
# |
205 |
|
|
206 |
return if ($i > 0); # Excel doesn't support repeatable fields |
return if ($i > 0); # Excel doesn't support repeatable fields |
207 |
|
|
222 |
#print STDERR "--$1-> $format -[",length($format),"] "; |
#print STDERR "--$1-> $format -[",length($format),"] "; |
223 |
if ($row->{$1}) { |
if ($row->{$1}) { |
224 |
my $tmp = $row->{$1}; |
my $tmp = $row->{$1}; |
|
if ($codepage) { |
|
|
$tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert"; |
|
|
} |
|
225 |
$display .= $prefix . $tmp; |
$display .= $prefix . $tmp; |
226 |
$swish .= $tmp." "; |
$swish .= $tmp." "; |
227 |
#print STDERR " == $tmp"; |
#print STDERR " == $tmp"; |
230 |
} elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) { |
} elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) { |
231 |
$prefix .= $1 if ($display); |
$prefix .= $1 if ($display); |
232 |
} else { |
} else { |
233 |
print STDERR "unparsed format: $format\n"; |
#print STDERR "unparsed format: $format\n"; |
234 |
$prefix .= $format; |
$prefix .= $format; |
235 |
$format = ""; |
$format = ""; |
236 |
} |
} |