line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::ParseExcel::FmtJapan; |
2
|
5
|
|
|
5
|
|
6449
|
use utf8; |
|
5
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
48
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
############################################################################### |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Spreadsheet::ParseExcel::FmtJapan - A class for Cell formats. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Used in conjunction with Spreadsheet::ParseExcel. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright (c) 2014 Douglas Wilson |
11
|
|
|
|
|
|
|
# Copyright (c) 2009-2013 John McNamara |
12
|
|
|
|
|
|
|
# Copyright (c) 2006-2008 Gabor Szabo |
13
|
|
|
|
|
|
|
# Copyright (c) 2000-2006 Kawai Takanori |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# perltidy with standard settings. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# Documentation after __END__ |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
212
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
157
|
|
21
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
226
|
|
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
5
|
|
2628
|
use Encode qw(find_encoding decode); |
|
5
|
|
|
|
|
35636
|
|
|
5
|
|
|
|
|
430
|
|
24
|
5
|
|
|
5
|
|
37
|
use base 'Spreadsheet::ParseExcel::FmtDefault'; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
3507
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.65'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %FormatTable = ( |
28
|
|
|
|
|
|
|
0x00 => 'General', |
29
|
|
|
|
|
|
|
0x01 => '0', |
30
|
|
|
|
|
|
|
0x02 => '0.00', |
31
|
|
|
|
|
|
|
0x03 => '#,##0', |
32
|
|
|
|
|
|
|
0x04 => '#,##0.00', |
33
|
|
|
|
|
|
|
0x05 => '(\\#,##0_);(\\#,##0)', |
34
|
|
|
|
|
|
|
0x06 => '(\\#,##0_);[Red](\\#,##0)', |
35
|
|
|
|
|
|
|
0x07 => '(\\#,##0.00_);(\\#,##0.00_)', |
36
|
|
|
|
|
|
|
0x08 => '(\\#,##0.00_);[Red](\\#,##0.00_)', |
37
|
|
|
|
|
|
|
0x09 => '0%', |
38
|
|
|
|
|
|
|
0x0A => '0.00%', |
39
|
|
|
|
|
|
|
0x0B => '0.00E+00', |
40
|
|
|
|
|
|
|
0x0C => '# ?/?', |
41
|
|
|
|
|
|
|
0x0D => '# ??/??', |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# 0x0E => 'm/d/yy', |
44
|
|
|
|
|
|
|
0x0E => 'yyyy/m/d', |
45
|
|
|
|
|
|
|
0x0F => 'd-mmm-yy', |
46
|
|
|
|
|
|
|
0x10 => 'd-mmm', |
47
|
|
|
|
|
|
|
0x11 => 'mmm-yy', |
48
|
|
|
|
|
|
|
0x12 => 'h:mm AM/PM', |
49
|
|
|
|
|
|
|
0x13 => 'h:mm:ss AM/PM', |
50
|
|
|
|
|
|
|
0x14 => 'h:mm', |
51
|
|
|
|
|
|
|
0x15 => 'h:mm:ss', |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# 0x16 => 'm/d/yy h:mm', |
54
|
|
|
|
|
|
|
0x16 => 'yyyy/m/d h:mm', |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#0x17-0x24 -- Differs in Natinal |
57
|
|
|
|
|
|
|
0x1E => 'm/d/yy', |
58
|
|
|
|
|
|
|
0x1F => 'yyyy"年"m"月"d"日"', |
59
|
|
|
|
|
|
|
0x20 => 'h"時"mm"分"', |
60
|
|
|
|
|
|
|
0x21 => 'h"時"mm"分"ss"秒"', |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#0x17-0x24 -- Differs in Natinal |
63
|
|
|
|
|
|
|
0x25 => '(#,##0_);(#,##0)', |
64
|
|
|
|
|
|
|
0x26 => '(#,##0_);[Red](#,##0)', |
65
|
|
|
|
|
|
|
0x27 => '(#,##0.00);(#,##0.00)', |
66
|
|
|
|
|
|
|
0x28 => '(#,##0.00);[Red](#,##0.00)', |
67
|
|
|
|
|
|
|
0x29 => '_(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)', |
68
|
|
|
|
|
|
|
0x2A => '_(\\*#,##0_);_(\\*(#,##0);_(*"-"_);_(@_)', |
69
|
|
|
|
|
|
|
0x2B => '_(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)', |
70
|
|
|
|
|
|
|
0x2C => '_(\\*#,##0.00_);_(\\*(#,##0.00);_(*"-"??_);_(@_)', |
71
|
|
|
|
|
|
|
0x2D => 'mm:ss', |
72
|
|
|
|
|
|
|
0x2E => '[h]:mm:ss', |
73
|
|
|
|
|
|
|
0x2F => 'mm:ss.0', |
74
|
|
|
|
|
|
|
0x30 => '##0.0E+0', |
75
|
|
|
|
|
|
|
0x31 => '@', |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
0x37 => 'yyyy"年"m"月"', |
78
|
|
|
|
|
|
|
0x38 => 'm"月"d"日"', |
79
|
|
|
|
|
|
|
0x39 => 'ge.m.d', |
80
|
|
|
|
|
|
|
0x3A => 'ggge"年"m"月"d"日"', |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
84
|
|
|
|
|
|
|
# new (for Spreadsheet::ParseExcel::FmtJapan) |
85
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
86
|
|
|
|
|
|
|
sub new { |
87
|
5
|
|
|
5
|
0
|
71
|
my ( $class, %args ) = @_; |
88
|
5
|
|
100
|
|
|
39
|
my $encoding = $args{Code} || $args{encoding}; |
89
|
5
|
|
|
|
|
21
|
my $self = { Code => $encoding }; |
90
|
5
|
100
|
|
|
|
19
|
if($encoding){ |
91
|
|
|
|
|
|
|
$self->{encoding} = find_encoding($encoding eq 'sjis' ? 'cp932' : $encoding) |
92
|
2
|
50
|
|
|
|
17
|
or do{ |
|
|
50
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
require Carp; |
94
|
0
|
|
|
|
|
0
|
Carp::croak(qq{Unknown encoding '$encoding'}); |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
} |
97
|
5
|
|
|
|
|
39262
|
return bless $self, $class; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
101
|
|
|
|
|
|
|
# TextFmt (for Spreadsheet::ParseExcel::FmtJapan) |
102
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
103
|
|
|
|
|
|
|
sub TextFmt { |
104
|
250
|
|
|
250
|
0
|
456
|
my ( $self, $text, $input_encoding ) = @_; |
105
|
250
|
100
|
|
|
|
687
|
if(!defined $input_encoding){ |
|
|
100
|
|
|
|
|
|
106
|
102
|
|
|
|
|
141
|
$input_encoding = 'utf8'; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif($input_encoding eq '_native_'){ |
109
|
80
|
|
|
|
|
108
|
$input_encoding = 'cp932'; # Shift_JIS in Microsoft products |
110
|
|
|
|
|
|
|
} |
111
|
250
|
|
|
|
|
684
|
$text = decode($input_encoding, $text); |
112
|
250
|
100
|
|
|
|
84179
|
return $self->{Code} ? $self->{encoding}->encode($text) : $text; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
115
|
|
|
|
|
|
|
# FmtStringDef (for Spreadsheet::ParseExcel::FmtJapan) |
116
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
117
|
|
|
|
|
|
|
sub FmtStringDef { |
118
|
56
|
|
|
56
|
0
|
85
|
my ( $self, $format_index, $book ) = @_; |
119
|
56
|
|
|
|
|
252
|
return $self->SUPER::FmtStringDef( $format_index, $book, \%FormatTable ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
123
|
|
|
|
|
|
|
# CnvNengo (for Spreadsheet::ParseExcel::FmtJapan) |
124
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Convert A.D. into Japanese Nengo (aka Gengo) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my @Nengo = ( |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
name => '平成', # Heisei |
131
|
|
|
|
|
|
|
abbr_name => 'H', |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
base => 1988, |
134
|
|
|
|
|
|
|
start => 19890108, |
135
|
|
|
|
|
|
|
}, |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
name => '昭和', # Showa |
138
|
|
|
|
|
|
|
abbr_name => 'S', |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
base => 1925, |
141
|
|
|
|
|
|
|
start => 19261225, |
142
|
|
|
|
|
|
|
}, |
143
|
|
|
|
|
|
|
{ |
144
|
|
|
|
|
|
|
name => '大正', # Taisho |
145
|
|
|
|
|
|
|
abbr_name => 'T', |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
base => 1911, |
148
|
|
|
|
|
|
|
start => 19120730, |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
{ |
151
|
|
|
|
|
|
|
name => '明治', # Meiji |
152
|
|
|
|
|
|
|
abbr_name => 'M', |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
base => 1867, |
155
|
|
|
|
|
|
|
start => 18680908, |
156
|
|
|
|
|
|
|
}, |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Usage: CnvNengo(name => @tm) or CnvNeng(abbr_name => @tm) |
160
|
|
|
|
|
|
|
sub CnvNengo { |
161
|
8
|
|
|
8
|
0
|
21
|
my ( $kind, @tm ) = @_; |
162
|
8
|
|
|
|
|
12
|
my $year = $tm[5] + 1900; |
163
|
8
|
|
|
|
|
15
|
my $wk = ($year * 10000) + ($tm[4] * 100) + ($tm[3] * 1); |
164
|
|
|
|
|
|
|
#my $wk = sprintf( '%04d%02d%02d', $year, $tm[4], $tm[3] ); |
165
|
8
|
|
|
|
|
14
|
foreach my $nengo(@Nengo){ |
166
|
20
|
100
|
|
|
|
46
|
if( $wk >= $nengo->{start} ){ |
167
|
8
|
|
|
|
|
45
|
return $nengo->{$kind} . ($year - $nengo->{base}); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
0
|
|
|
|
|
|
return $year; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |