| 1 | package Spreadsheet::ParseExcel::FmtJapan2; | ||
| 2 | |||
| 3 | ############################################################################### | ||
| 4 | # | ||
| 5 | # Spreadsheet::ParseExcel::FmtJapan2 - A class for Cell formats. | ||
| 6 | # | ||
| 7 | # Used in conjunction with Spreadsheet::ParseExcel. | ||
| 8 | # | ||
| 9 | # Copyright (c) 2014 Douglas Wilson | ||
| 10 | # Copyright (c) 2009-2013 John McNamara | ||
| 11 | # Copyright (c) 2006-2008 Gabor Szabo | ||
| 12 | # Copyright (c) 2000-2006 Kawai Takanori | ||
| 13 | # | ||
| 14 | # perltidy with standard settings. | ||
| 15 | # | ||
| 16 | # Documentation after __END__ | ||
| 17 | # | ||
| 18 | |||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | |||
| 22 | use Jcode; | ||
| 23 | use Unicode::Map; | ||
| 24 | use base 'Spreadsheet::ParseExcel::FmtJapan'; | ||
| 25 | our $VERSION = '0.66'; | ||
| 26 | |||
| 27 | #------------------------------------------------------------------------------ | ||
| 28 | # new (for Spreadsheet::ParseExcel::FmtJapan2) | ||
| 29 | #------------------------------------------------------------------------------ | ||
| 30 | sub new { | ||
| 31 | my ( $sPkg, %hKey ) = @_; | ||
| 32 | my $oMap = Unicode::Map->new('CP932Excel'); | ||
| 33 | die "NO MAP FILE CP932Excel!!" | ||
| 34 | unless ( -r Unicode::Map->mapping("CP932Excel") ); | ||
| 35 | |||
| 36 | my $oThis = { | ||
| 37 | Code => $hKey{Code}, | ||
| 38 | _UniMap => $oMap, | ||
| 39 | }; | ||
| 40 | bless $oThis; | ||
| 41 | $oThis->SUPER::new(%hKey); | ||
| 42 | return $oThis; | ||
| 43 | } | ||
| 44 | |||
| 45 | #------------------------------------------------------------------------------ | ||
| 46 | # TextFmt (for Spreadsheet::ParseExcel::FmtJapan2) | ||
| 47 | #------------------------------------------------------------------------------ | ||
| 48 | sub TextFmt { | ||
| 49 | my ( $oThis, $sTxt, $sCode ) = @_; | ||
| 50 | |||
| 51 | # $sCode = 'sjis' if((! defined($sCode)) || ($sCode eq '_native_')); | ||
| 52 | if ( $oThis->{Code} ) { | ||
| 53 | if ( !defined($sCode) ) { | ||
| 54 | $sTxt =~ s/(.)/\x00$1/sg; | ||
| 55 | $sTxt = $oThis->{_UniMap}->from_unicode($sTxt); | ||
| 56 | } | ||
| 57 | elsif ( $sCode eq 'ucs2' ) { | ||
| 58 | $sTxt = $oThis->{_UniMap}->from_unicode($sTxt); | ||
| 59 | } | ||
| 60 | return Jcode::convert( $sTxt, $oThis->{Code}, 'sjis' ); | ||
| 61 | } | ||
| 62 | else { | ||
| 63 | return $sTxt; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | 1; | ||
| 67 | |||
| 68 | __END__ |