File Coverage

blib/lib/Spreadsheet/XLSX/Fmt2007.pm
Criterion Covered Total %
statement 35 50 70.0
branch 14 28 50.0
condition 2 18 11.1
subroutine 7 9 77.7
pod 0 6 0.0
total 58 111 52.2


line stmt bran cond sub pod time code
1             # This code is adapted for Excel 2007 from:
2             # Spreadsheet::XLSX::FmtDefault
3             # by Kawai, Takanori (Hippo2000) 2001.2.2
4             # This Program is ALPHA version.
5             #==============================================================================
6             package Spreadsheet::XLSX::Fmt2007;
7 6     6   50 use strict;
  6         15  
  6         208  
8 6     6   33 use warnings;
  6         14  
  6         208  
9              
10 6     6   3353 use Spreadsheet::XLSX::Utility2007 qw(ExcelFmt);
  6         21  
  6         4275  
11             our $VERSION = '0.16'; #
12              
13             my %hFmtDefault = (
14             0x00 => '@',
15             0x01 => '0',
16             0x02 => '0.00',
17             0x03 => '#,##0',
18             0x04 => '#,##0.00',
19             0x05 => '($#,##0_);($#,##0)',
20             0x06 => '($#,##0_);[RED]($#,##0)',
21             0x07 => '($#,##0.00_);($#,##0.00_)',
22             0x08 => '($#,##0.00_);[RED]($#,##0.00_)',
23             0x09 => '0%',
24             0x0A => '0.00%',
25             0x0B => '0.00E+00',
26             0x0C => '# ?/?',
27             0x0D => '# ??/??',
28             0x0E => 'yyyy-mm-dd',
29             0x0F => 'd-mmm-yy',
30             0x10 => 'd-mmm',
31             0x11 => 'mmm-yy',
32             0x12 => 'h:mm AM/PM',
33             0x13 => 'h:mm:ss AM/PM',
34             0x14 => 'h:mm',
35             0x15 => 'h:mm:ss',
36             0x16 => 'm-d-yy h:mm',
37              
38             #0x17-0x24 -- Differs in Natinal
39             0x25 => '(#,##0_);(#,##0)',
40             0x26 => '(#,##0_);[RED](#,##0)',
41             0x27 => '(#,##0.00);(#,##0.00)',
42             0x28 => '(#,##0.00);[RED](#,##0.00)',
43             0x29 => '_(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)',
44             0x2A => '_($*#,##0_);_($*(#,##0);_(*"-"_);_(@_)',
45             0x2B => '_(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)',
46             0x2C => '_($*#,##0.00_);_($*(#,##0.00);_(*"-"??_);_(@_)',
47             0x2D => 'mm:ss',
48             0x2E => '[h]:mm:ss',
49             0x2F => 'mm:ss.0',
50             0x30 => '##0.0E+0',
51             0x31 => '@',
52             );
53              
54             #------------------------------------------------------------------------------
55             # new (for Spreadsheet::XLSX::Utility2007)
56             #------------------------------------------------------------------------------
57             sub new {
58 10     10 0 48 my ($sPkg, %hKey) = @_;
59 10         25 my $oThis = {};
60 10         30 bless $oThis;
61 10         38 return $oThis;
62             }
63              
64             #------------------------------------------------------------------------------
65             # TextFmt (for Spreadsheet::XLSX::Utility2007)
66             #------------------------------------------------------------------------------
67             sub TextFmt {
68 836     836 0 2333 my ($oThis, $sTxt, $sCode) = @_;
69 836 50 33     2923 return $sTxt if ((!defined($sCode)) || ($sCode eq '_native_'));
70 0         0 return pack('U*', unpack('n*', $sTxt));
71             }
72              
73             #------------------------------------------------------------------------------
74             # FmtStringDef (for Spreadsheet::XLSX::Utility2007)
75             #------------------------------------------------------------------------------
76             sub FmtStringDef {
77 0     0 0 0 my ($oThis, $iFmtIdx, $oBook, $rhFmt) = @_;
78 0         0 my $sFmtStr = $oBook->{FormatStr}->{$iFmtIdx};
79              
80 0 0 0     0 if (!(defined($sFmtStr)) && defined($rhFmt)) {
81 0         0 $sFmtStr = $rhFmt->{$iFmtIdx};
82             }
83 0 0       0 $sFmtStr = $hFmtDefault{$iFmtIdx} unless ($sFmtStr);
84 0         0 return $sFmtStr;
85             }
86              
87             #------------------------------------------------------------------------------
88             # FmtString (for Spreadsheet::XLSX::Utility2007)
89             #------------------------------------------------------------------------------
90             sub FmtString {
91 1622     1622 0 2725 my ($oThis, $oCell, $oBook) = @_;
92              
93 1622         2169 my $sFmtStr; # = $oThis->FmtStringDef(
94              
95             # $oBook->{Format}[$oCell->{FormatNo}]->{FmtIdx}, $oBook);
96              
97 1622 50       2968 unless (defined($sFmtStr)) {
98 1622 100       3767 if ($oCell->{Type} eq 'Numeric') {
    100          
99 784 100       2277 if ($oCell->{Format}) {
    100          
100 395         722 $sFmtStr = $oCell->{Format};
101             } elsif (int($oCell->{Val}) != $oCell->{Val}) {
102 242         549 $sFmtStr = '0.00';
103             } else {
104 147         252 $sFmtStr = '0';
105             }
106             } elsif ($oCell->{Type} eq 'Date') {
107 2 50       5 if ($oCell->{Format}) {
    0          
108 2         6 $sFmtStr = $oCell->{Format};
109             } elsif (int($oCell->{Val}) <= 0) {
110 0         0 $sFmtStr = 'h:mm:ss';
111             } else {
112 0         0 $sFmtStr = 'm-d-yy';
113             }
114             } else {
115 836         1441 $sFmtStr = '@';
116             }
117             }
118 1622         3450 return $sFmtStr;
119             }
120              
121             #------------------------------------------------------------------------------
122             # ValFmt (for Spreadsheet::XLSX::Utility2007)
123             #------------------------------------------------------------------------------
124             sub ValFmt {
125 1622     1622 0 3140 my ($oThis, $oCell, $oBook) = @_;
126              
127 1622         2566 my ($Dt, $iFmtIdx, $iNumeric, $Flg1904);
128              
129 1622 100       3375 if ($oCell->{Type} eq 'Text') {
130 836 50 33     4247 $Dt = ((defined $oCell->{Val}) && ($oCell->{Val} ne '')) ? $oThis->TextFmt($oCell->{Val}, $oCell->{Code}) : '';
131             } else {
132 786         1320 $Dt = $oCell->{Val};
133             }
134 1622         3195 $Flg1904 = $oBook->{Flg1904};
135 1622         3208 my $sFmtStr = $oThis->FmtString($oCell, $oBook);
136 1622         4226 return ExcelFmt($sFmtStr, $Dt, $Flg1904, $oCell->{Type});
137             }
138              
139             #------------------------------------------------------------------------------
140             # ChkType (for Spreadsheet::XLSX::Utility2007)
141             #------------------------------------------------------------------------------
142             sub ChkType {
143 0     0 0   my ($oPkg, $iNumeric, $iFmtIdx) = @_;
144 0 0         if ($iNumeric) {
145 0 0 0       if ( (($iFmtIdx >= 0x0E) && ($iFmtIdx <= 0x16))
      0        
      0        
146             || (($iFmtIdx >= 0x2D) && ($iFmtIdx <= 0x2F))) {
147 0           return "Date";
148             } else {
149 0           return "Numeric";
150             }
151             } else {
152 0           return "Text";
153             }
154             }
155             1;
156              
157             __END__