← Index
NYTProf Performance Profile   « line view »
For t/bug-md-11.t
  Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

Filename/home/micha/.plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/Spreadsheet/ParseExcel.pm
StatementsExecuted 76 statements in 7.43ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.23ms5.79msSpreadsheet::ParseExcel::::BEGIN@21Spreadsheet::ParseExcel::BEGIN@21
111960µs2.77msSpreadsheet::ParseExcel::::BEGIN@27Spreadsheet::ParseExcel::BEGIN@27
111818µs884µsSpreadsheet::ParseExcel::::BEGIN@32Spreadsheet::ParseExcel::BEGIN@32
111439µs3.80msSpreadsheet::ParseExcel::::BEGIN@36Spreadsheet::ParseExcel::BEGIN@36
111383µs434µsSpreadsheet::ParseExcel::::BEGIN@31Spreadsheet::ParseExcel::BEGIN@31
111349µs404µsSpreadsheet::ParseExcel::::BEGIN@26Spreadsheet::ParseExcel::BEGIN@26
111314µs364µsSpreadsheet::ParseExcel::::BEGIN@35Spreadsheet::ParseExcel::BEGIN@35
111117µs145µsSpreadsheet::ParseExcel::::BEGIN@34Spreadsheet::ParseExcel::BEGIN@34
111105µs134µsSpreadsheet::ParseExcel::::BEGIN@33Spreadsheet::ParseExcel::BEGIN@33
11113µs14µsSpreadsheet::ParseExcel::::BEGIN@17Spreadsheet::ParseExcel::BEGIN@17
1118µs20µsSpreadsheet::ParseExcel::::BEGIN@63Spreadsheet::ParseExcel::BEGIN@63
1117µs10µsSpreadsheet::ParseExcel::::BEGIN@2628Spreadsheet::ParseExcel::BEGIN@2628
1116µs6µsSpreadsheet::ParseExcel::::BEGIN@19Spreadsheet::ParseExcel::BEGIN@19
1116µs30µsSpreadsheet::ParseExcel::::BEGIN@58Spreadsheet::ParseExcel::BEGIN@58
1115µs18µsSpreadsheet::ParseExcel::::BEGIN@2705Spreadsheet::ParseExcel::BEGIN@2705
1115µs17µsSpreadsheet::ParseExcel::::BEGIN@66Spreadsheet::ParseExcel::BEGIN@66
1115µs23µsSpreadsheet::ParseExcel::::BEGIN@22Spreadsheet::ParseExcel::BEGIN@22
1114µs10µsSpreadsheet::ParseExcel::::BEGIN@24Spreadsheet::ParseExcel::BEGIN@24
6614µs4µsSpreadsheet::ParseExcel::::__ANON__Spreadsheet::ParseExcel::__ANON__ (xsub)
1114µs60µsSpreadsheet::ParseExcel::::BEGIN@23Spreadsheet::ParseExcel::BEGIN@23
1114µs19µsSpreadsheet::ParseExcel::::BEGIN@18Spreadsheet::ParseExcel::BEGIN@18
1113µs19µsSpreadsheet::ParseExcel::::BEGIN@59Spreadsheet::ParseExcel::BEGIN@59
1113µs18µsSpreadsheet::ParseExcel::::BEGIN@76Spreadsheet::ParseExcel::BEGIN@76
1113µs17µsSpreadsheet::ParseExcel::::BEGIN@60Spreadsheet::ParseExcel::BEGIN@60
1113µs17µsSpreadsheet::ParseExcel::::BEGIN@75Spreadsheet::ParseExcel::BEGIN@75
1113µs16µsSpreadsheet::ParseExcel::::BEGIN@61Spreadsheet::ParseExcel::BEGIN@61
1113µs16µsSpreadsheet::ParseExcel::::BEGIN@70Spreadsheet::ParseExcel::BEGIN@70
1113µs16µsSpreadsheet::ParseExcel::::BEGIN@67Spreadsheet::ParseExcel::BEGIN@67
1113µs15µsSpreadsheet::ParseExcel::::BEGIN@78Spreadsheet::ParseExcel::BEGIN@78
1113µs16µsSpreadsheet::ParseExcel::::BEGIN@64Spreadsheet::ParseExcel::BEGIN@64
1113µs15µsSpreadsheet::ParseExcel::::BEGIN@68Spreadsheet::ParseExcel::BEGIN@68
1113µs15µsSpreadsheet::ParseExcel::::BEGIN@72Spreadsheet::ParseExcel::BEGIN@72
1113µs16µsSpreadsheet::ParseExcel::::BEGIN@77Spreadsheet::ParseExcel::BEGIN@77
1113µs15µsSpreadsheet::ParseExcel::::BEGIN@81Spreadsheet::ParseExcel::BEGIN@81
1113µs15µsSpreadsheet::ParseExcel::::BEGIN@62Spreadsheet::ParseExcel::BEGIN@62
0000s0sSpreadsheet::ParseExcel::::ColorIdxToRGBSpreadsheet::ParseExcel::ColorIdxToRGB
0000s0sSpreadsheet::ParseExcel::::DecodeBoolErrSpreadsheet::ParseExcel::DecodeBoolErr
0000s0sSpreadsheet::ParseExcel::::InitStreamSpreadsheet::ParseExcel::InitStream
0000s0sSpreadsheet::ParseExcel::::MakeKeySpreadsheet::ParseExcel::MakeKey
0000s0sSpreadsheet::ParseExcel::::QueryNextSpreadsheet::ParseExcel::QueryNext
0000s0sSpreadsheet::ParseExcel::::SetDecryptSpreadsheet::ParseExcel::SetDecrypt
0000s0sSpreadsheet::ParseExcel::::SetEventHandlerSpreadsheet::ParseExcel::SetEventHandler
0000s0sSpreadsheet::ParseExcel::::SetEventHandlersSpreadsheet::ParseExcel::SetEventHandlers
0000s0sSpreadsheet::ParseExcel::::SkipBytesSpreadsheet::ParseExcel::SkipBytes
0000s0sSpreadsheet::ParseExcel::::VerifyPasswordSpreadsheet::ParseExcel::VerifyPassword
0000s0sSpreadsheet::ParseExcel::::_NewCellSpreadsheet::ParseExcel::_NewCell
0000s0sSpreadsheet::ParseExcel::::_ParseNameAreaSpreadsheet::ParseExcel::_ParseNameArea
0000s0sSpreadsheet::ParseExcel::::_ParseNameArea95Spreadsheet::ParseExcel::_ParseNameArea95
0000s0sSpreadsheet::ParseExcel::::_SetDimensionSpreadsheet::ParseExcel::_SetDimension
0000s0sSpreadsheet::ParseExcel::::_SwapForUnicodeSpreadsheet::ParseExcel::_SwapForUnicode
0000s0sSpreadsheet::ParseExcel::::_convBIFF8StringSpreadsheet::ParseExcel::_convBIFF8String
0000s0sSpreadsheet::ParseExcel::::_convDvalSpreadsheet::ParseExcel::_convDval
0000s0sSpreadsheet::ParseExcel::::_convert_col_widthSpreadsheet::ParseExcel::_convert_col_width
0000s0sSpreadsheet::ParseExcel::::_decode_rk_numberSpreadsheet::ParseExcel::_decode_rk_number
0000s0sSpreadsheet::ParseExcel::::_get_contentSpreadsheet::ParseExcel::_get_content
0000s0sSpreadsheet::ParseExcel::::_getguidSpreadsheet::ParseExcel::_getguid
0000s0sSpreadsheet::ParseExcel::::_getustrSpreadsheet::ParseExcel::_getustr
0000s0sSpreadsheet::ParseExcel::::_subArraySpreadsheet::ParseExcel::_subArray
0000s0sSpreadsheet::ParseExcel::::_subBOFSpreadsheet::ParseExcel::_subBOF
0000s0sSpreadsheet::ParseExcel::::_subBlankSpreadsheet::ParseExcel::_subBlank
0000s0sSpreadsheet::ParseExcel::::_subBoolErrSpreadsheet::ParseExcel::_subBoolErr
0000s0sSpreadsheet::ParseExcel::::_subBoundSheetSpreadsheet::ParseExcel::_subBoundSheet
0000s0sSpreadsheet::ParseExcel::::_subColInfoSpreadsheet::ParseExcel::_subColInfo
0000s0sSpreadsheet::ParseExcel::::_subContinueSpreadsheet::ParseExcel::_subContinue
0000s0sSpreadsheet::ParseExcel::::_subDefColWidthSpreadsheet::ParseExcel::_subDefColWidth
0000s0sSpreadsheet::ParseExcel::::_subDefaultRowHeightSpreadsheet::ParseExcel::_subDefaultRowHeight
0000s0sSpreadsheet::ParseExcel::::_subFlg1904Spreadsheet::ParseExcel::_subFlg1904
0000s0sSpreadsheet::ParseExcel::::_subFontSpreadsheet::ParseExcel::_subFont
0000s0sSpreadsheet::ParseExcel::::_subFooterSpreadsheet::ParseExcel::_subFooter
0000s0sSpreadsheet::ParseExcel::::_subFormatSpreadsheet::ParseExcel::_subFormat
0000s0sSpreadsheet::ParseExcel::::_subFormulaSpreadsheet::ParseExcel::_subFormula
0000s0sSpreadsheet::ParseExcel::::_subGetContentSpreadsheet::ParseExcel::_subGetContent
0000s0sSpreadsheet::ParseExcel::::_subHPageBreakSpreadsheet::ParseExcel::_subHPageBreak
0000s0sSpreadsheet::ParseExcel::::_subHcenterSpreadsheet::ParseExcel::_subHcenter
0000s0sSpreadsheet::ParseExcel::::_subHeaderSpreadsheet::ParseExcel::_subHeader
0000s0sSpreadsheet::ParseExcel::::_subHyperlinkSpreadsheet::ParseExcel::_subHyperlink
0000s0sSpreadsheet::ParseExcel::::_subIntegerSpreadsheet::ParseExcel::_subInteger
0000s0sSpreadsheet::ParseExcel::::_subLabelSpreadsheet::ParseExcel::_subLabel
0000s0sSpreadsheet::ParseExcel::::_subLabelSSTSpreadsheet::ParseExcel::_subLabelSST
0000s0sSpreadsheet::ParseExcel::::_subMarginSpreadsheet::ParseExcel::_subMargin
0000s0sSpreadsheet::ParseExcel::::_subMergeAreaSpreadsheet::ParseExcel::_subMergeArea
0000s0sSpreadsheet::ParseExcel::::_subMulBlankSpreadsheet::ParseExcel::_subMulBlank
0000s0sSpreadsheet::ParseExcel::::_subMulRKSpreadsheet::ParseExcel::_subMulRK
0000s0sSpreadsheet::ParseExcel::::_subNameSpreadsheet::ParseExcel::_subName
0000s0sSpreadsheet::ParseExcel::::_subNumberSpreadsheet::ParseExcel::_subNumber
0000s0sSpreadsheet::ParseExcel::::_subPaletteSpreadsheet::ParseExcel::_subPalette
0000s0sSpreadsheet::ParseExcel::::_subPrintGridlinesSpreadsheet::ParseExcel::_subPrintGridlines
0000s0sSpreadsheet::ParseExcel::::_subPrintHeadersSpreadsheet::ParseExcel::_subPrintHeaders
0000s0sSpreadsheet::ParseExcel::::_subRKSpreadsheet::ParseExcel::_subRK
0000s0sSpreadsheet::ParseExcel::::_subRStringSpreadsheet::ParseExcel::_subRString
0000s0sSpreadsheet::ParseExcel::::_subRowSpreadsheet::ParseExcel::_subRow
0000s0sSpreadsheet::ParseExcel::::_subSETUPSpreadsheet::ParseExcel::_subSETUP
0000s0sSpreadsheet::ParseExcel::::_subSSTSpreadsheet::ParseExcel::_subSST
0000s0sSpreadsheet::ParseExcel::::_subSheetLayoutSpreadsheet::ParseExcel::_subSheetLayout
0000s0sSpreadsheet::ParseExcel::::_subStandardWidthSpreadsheet::ParseExcel::_subStandardWidth
0000s0sSpreadsheet::ParseExcel::::_subStrWkSpreadsheet::ParseExcel::_subStrWk
0000s0sSpreadsheet::ParseExcel::::_subStringSpreadsheet::ParseExcel::_subString
0000s0sSpreadsheet::ParseExcel::::_subVPageBreakSpreadsheet::ParseExcel::_subVPageBreak
0000s0sSpreadsheet::ParseExcel::::_subVcenterSpreadsheet::ParseExcel::_subVcenter
0000s0sSpreadsheet::ParseExcel::::_subWSBOOLSpreadsheet::ParseExcel::_subWSBOOL
0000s0sSpreadsheet::ParseExcel::::_subWindow1Spreadsheet::ParseExcel::_subWindow1
0000s0sSpreadsheet::ParseExcel::::_subWriteAccessSpreadsheet::ParseExcel::_subWriteAccess
0000s0sSpreadsheet::ParseExcel::::_subXFSpreadsheet::ParseExcel::_subXF
0000s0sSpreadsheet::ParseExcel::::errorSpreadsheet::ParseExcel::error
0000s0sSpreadsheet::ParseExcel::::error_codeSpreadsheet::ParseExcel::error_code
0000s0sSpreadsheet::ParseExcel::::md5stateSpreadsheet::ParseExcel::md5state
0000s0sSpreadsheet::ParseExcel::::newSpreadsheet::ParseExcel::new
0000s0sSpreadsheet::ParseExcel::::parseSpreadsheet::ParseExcel::parse
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Spreadsheet::ParseExcel;
2
3##############################################################################
4#
5# Spreadsheet::ParseExcel - Extract information from an Excel file.
6#
7# Copyright (c) 2014 Douglas Wilson
8# Copyright (c) 2009-2013 John McNamara
9# Copyright (c) 2006-2008 Gabor Szabo
10# Copyright (c) 2000-2008 Takanori Kawai
11#
12# perltidy with standard settings.
13#
14# Documentation after __END__
15#
16
17224µs216µs
# spent 14µs (13+2) within Spreadsheet::ParseExcel::BEGIN@17 which was called: # once (13µs+2µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 17
use strict;
# spent 14µs making 1 call to Spreadsheet::ParseExcel::BEGIN@17 # spent 2µs making 1 call to strict::import
18213µs234µs
# spent 19µs (4+16) within Spreadsheet::ParseExcel::BEGIN@18 which was called: # once (4µs+16µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 18
use warnings;
# spent 19µs making 1 call to Spreadsheet::ParseExcel::BEGIN@18 # spent 16µs making 1 call to warnings::import
19228µs16µs
# spent 6µs within Spreadsheet::ParseExcel::BEGIN@19 which was called: # once (6µs+0s) by Spreadsheet::ParseXLSX::BEGIN@14 at line 19
use 5.008;
# spent 6µs making 1 call to Spreadsheet::ParseExcel::BEGIN@19
20
21299µs25.80ms
# spent 5.79ms (4.23+1.56) within Spreadsheet::ParseExcel::BEGIN@21 which was called: # once (4.23ms+1.56ms) by Spreadsheet::ParseXLSX::BEGIN@14 at line 21
use OLE::Storage_Lite;
# spent 5.79ms making 1 call to Spreadsheet::ParseExcel::BEGIN@21 # spent 9µs making 1 call to Exporter::import
22216µs241µs
# spent 23µs (5+18) within Spreadsheet::ParseExcel::BEGIN@22 which was called: # once (5µs+18µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 22
use File::Basename qw(fileparse);
# spent 23µs making 1 call to Spreadsheet::ParseExcel::BEGIN@22 # spent 18µs making 1 call to Exporter::import
23214µs2116µs
# spent 60µs (4+56) within Spreadsheet::ParseExcel::BEGIN@23 which was called: # once (4µs+56µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 23
use IO::File;
# spent 60µs making 1 call to Spreadsheet::ParseExcel::BEGIN@23 # spent 56µs making 1 call to Exporter::import
24212µs217µs
# spent 10µs (4+6) within Spreadsheet::ParseExcel::BEGIN@24 which was called: # once (4µs+6µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 24
use Config;
# spent 10µs making 1 call to Spreadsheet::ParseExcel::BEGIN@24 # spent 6µs making 1 call to Config::import
25
26280µs2420µs
# spent 404µs (349+55) within Spreadsheet::ParseExcel::BEGIN@26 which was called: # once (349µs+55µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 26
use Crypt::RC4;
# spent 404µs making 1 call to Spreadsheet::ParseExcel::BEGIN@26 # spent 17µs making 1 call to Exporter::import
27283µs22.78ms
# spent 2.77ms (960µs+1.81) within Spreadsheet::ParseExcel::BEGIN@27 which was called: # once (960µs+1.81ms) by Spreadsheet::ParseXLSX::BEGIN@14 at line 27
use Digest::Perl::MD5;
# spent 2.77ms making 1 call to Spreadsheet::ParseExcel::BEGIN@27 # spent 12µs making 1 call to Exporter::import
28
291400nsour $VERSION = '0.66';
30
31281µs2434µs
# spent 434µs (383+51) within Spreadsheet::ParseExcel::BEGIN@31 which was called: # once (383µs+51µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 31
use Spreadsheet::ParseExcel::Workbook;
# spent 434µs making 1 call to Spreadsheet::ParseExcel::BEGIN@31 # spent 600ns making 1 call to Spreadsheet::ParseExcel::__ANON__
32288µs2885µs
# spent 884µs (818+66) within Spreadsheet::ParseExcel::BEGIN@32 which was called: # once (818µs+66µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 32
use Spreadsheet::ParseExcel::Worksheet;
# spent 884µs making 1 call to Spreadsheet::ParseExcel::BEGIN@32 # spent 600ns making 1 call to Spreadsheet::ParseExcel::__ANON__
33272µs2135µs
# spent 134µs (105+29) within Spreadsheet::ParseExcel::BEGIN@33 which was called: # once (105µs+29µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 33
use Spreadsheet::ParseExcel::Font;
# spent 134µs making 1 call to Spreadsheet::ParseExcel::BEGIN@33 # spent 700ns making 1 call to Spreadsheet::ParseExcel::__ANON__
34275µs2146µs
# spent 145µs (117+28) within Spreadsheet::ParseExcel::BEGIN@34 which was called: # once (117µs+28µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 34
use Spreadsheet::ParseExcel::Format;
# spent 145µs making 1 call to Spreadsheet::ParseExcel::BEGIN@34 # spent 700ns making 1 call to Spreadsheet::ParseExcel::__ANON__
35286µs2364µs
# spent 364µs (314+50) within Spreadsheet::ParseExcel::BEGIN@35 which was called: # once (314µs+50µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 35
use Spreadsheet::ParseExcel::Cell;
# spent 364µs making 1 call to Spreadsheet::ParseExcel::BEGIN@35 # spent 600ns making 1 call to Spreadsheet::ParseExcel::__ANON__
362118µs23.80ms
# spent 3.80ms (439µs+3.36) within Spreadsheet::ParseExcel::BEGIN@36 which was called: # once (439µs+3.36ms) by Spreadsheet::ParseXLSX::BEGIN@14 at line 36
use Spreadsheet::ParseExcel::FmtDefault;
# spent 3.80ms making 1 call to Spreadsheet::ParseExcel::BEGIN@36 # spent 800ns making 1 call to Spreadsheet::ParseExcel::__ANON__
37
381100nsmy $currentbook;
3914µsmy @aColor = (
40 '000000', # 0x00
41 'FFFFFF', 'FFFFFF', 'FFFFFF', 'FFFFFF',
42 'FFFFFF', 'FFFFFF', 'FFFFFF', '000000', # 0x08
43 'FFFFFF', 'FF0000', '00FF00', '0000FF',
44 'FFFF00', 'FF00FF', '00FFFF', '800000', # 0x10
45 '008000', '000080', '808000', '800080',
46 '008080', 'C0C0C0', '808080', '9999FF', # 0x18
47 '993366', 'FFFFCC', 'CCFFFF', '660066',
48 'FF8080', '0066CC', 'CCCCFF', '000080', # 0x20
49 'FF00FF', 'FFFF00', '00FFFF', '800080',
50 '800000', '008080', '0000FF', '00CCFF', # 0x28
51 'CCFFFF', 'CCFFCC', 'FFFF99', '99CCFF',
52 'FF99CC', 'CC99FF', 'FFCC99', '3366FF', # 0x30
53 '33CCCC', '99CC00', 'FFCC00', 'FF9900',
54 'FF6600', '666699', '969696', '003366', # 0x38
55 '339966', '003300', '333300', '993300',
56 '993366', '333399', '333333', '000000' # 0x40
57);
58219µs255µs
# spent 30µs (6+24) within Spreadsheet::ParseExcel::BEGIN@58 which was called: # once (6µs+24µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 58
use constant verExcel95 => 0x500;
# spent 30µs making 1 call to Spreadsheet::ParseExcel::BEGIN@58 # spent 24µs making 1 call to constant::import
59214µs235µs
# spent 19µs (3+16) within Spreadsheet::ParseExcel::BEGIN@59 which was called: # once (3µs+16µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 59
use constant verExcel97 => 0x600;
# spent 19µs making 1 call to Spreadsheet::ParseExcel::BEGIN@59 # spent 16µs making 1 call to constant::import
60211µs231µs
# spent 17µs (3+14) within Spreadsheet::ParseExcel::BEGIN@60 which was called: # once (3µs+14µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 60
use constant verBIFF2 => 0x00;
# spent 17µs making 1 call to Spreadsheet::ParseExcel::BEGIN@60 # spent 14µs making 1 call to constant::import
61211µs229µs
# spent 16µs (3+13) within Spreadsheet::ParseExcel::BEGIN@61 which was called: # once (3µs+13µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 61
use constant verBIFF3 => 0x02;
# spent 16µs making 1 call to Spreadsheet::ParseExcel::BEGIN@61 # spent 13µs making 1 call to constant::import
62211µs227µs
# spent 15µs (3+12) within Spreadsheet::ParseExcel::BEGIN@62 which was called: # once (3µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 62
use constant verBIFF4 => 0x04;
# spent 15µs making 1 call to Spreadsheet::ParseExcel::BEGIN@62 # spent 12µs making 1 call to constant::import
63213µs232µs
# spent 20µs (8+12) within Spreadsheet::ParseExcel::BEGIN@63 which was called: # once (8µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 63
use constant verBIFF5 => 0x08;
# spent 20µs making 1 call to Spreadsheet::ParseExcel::BEGIN@63 # spent 12µs making 1 call to constant::import
64211µs228µs
# spent 16µs (3+13) within Spreadsheet::ParseExcel::BEGIN@64 which was called: # once (3µs+13µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 64
use constant verBIFF8 => 0x18;
# spent 16µs making 1 call to Spreadsheet::ParseExcel::BEGIN@64 # spent 13µs making 1 call to constant::import
65
66212µs230µs
# spent 17µs (5+12) within Spreadsheet::ParseExcel::BEGIN@66 which was called: # once (5µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 66
use constant MS_BIFF_CRYPTO_NONE => 0;
# spent 17µs making 1 call to Spreadsheet::ParseExcel::BEGIN@66 # spent 12µs making 1 call to constant::import
67211µs230µs
# spent 16µs (3+13) within Spreadsheet::ParseExcel::BEGIN@67 which was called: # once (3µs+13µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 67
use constant MS_BIFF_CRYPTO_XOR => 1;
# spent 16µs making 1 call to Spreadsheet::ParseExcel::BEGIN@67 # spent 13µs making 1 call to constant::import
68215µs227µs
# spent 15µs (3+12) within Spreadsheet::ParseExcel::BEGIN@68 which was called: # once (3µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 68
use constant MS_BIFF_CRYPTO_RC4 => 2;
# spent 15µs making 1 call to Spreadsheet::ParseExcel::BEGIN@68 # spent 12µs making 1 call to constant::import
69
70212µs230µs
# spent 16µs (3+14) within Spreadsheet::ParseExcel::BEGIN@70 which was called: # once (3µs+14µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 70
use constant sizeof_BIFF_8_FILEPASS => ( 6 + 3 * 16 );
# spent 16µs making 1 call to Spreadsheet::ParseExcel::BEGIN@70 # spent 14µs making 1 call to constant::import
71
72216µs226µs
# spent 15µs (3+12) within Spreadsheet::ParseExcel::BEGIN@72 which was called: # once (3µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 72
use constant REKEY_BLOCK => 0x400;
# spent 15µs making 1 call to Spreadsheet::ParseExcel::BEGIN@72 # spent 12µs making 1 call to constant::import
73
74# Error code for some of the common parsing errors.
75212µs230µs
# spent 17µs (3+14) within Spreadsheet::ParseExcel::BEGIN@75 which was called: # once (3µs+14µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 75
use constant ErrorNone => 0;
# spent 17µs making 1 call to Spreadsheet::ParseExcel::BEGIN@75 # spent 14µs making 1 call to constant::import
76212µs234µs
# spent 18µs (3+15) within Spreadsheet::ParseExcel::BEGIN@76 which was called: # once (3µs+15µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 76
use constant ErrorNoFile => 1;
# spent 18µs making 1 call to Spreadsheet::ParseExcel::BEGIN@76 # spent 15µs making 1 call to constant::import
77211µs229µs
# spent 16µs (3+13) within Spreadsheet::ParseExcel::BEGIN@77 which was called: # once (3µs+13µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 77
use constant ErrorNoExcelData => 2;
# spent 16µs making 1 call to Spreadsheet::ParseExcel::BEGIN@77 # spent 13µs making 1 call to constant::import
78211µs227µs
# spent 15µs (3+12) within Spreadsheet::ParseExcel::BEGIN@78 which was called: # once (3µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 78
use constant ErrorFileEncrypted => 3;
# spent 15µs making 1 call to Spreadsheet::ParseExcel::BEGIN@78 # spent 12µs making 1 call to constant::import
79
80# Color index for the 'auto' color
8126.05ms227µs
# spent 15µs (3+12) within Spreadsheet::ParseExcel::BEGIN@81 which was called: # once (3µs+12µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 81
use constant AutoColor => 64;
# spent 15µs making 1 call to Spreadsheet::ParseExcel::BEGIN@81 # spent 12µs making 1 call to constant::import
82
8312µsour %error_strings = (
84 ErrorNone, '', # 0
85 ErrorNoFile, 'File not found', # 1
86 ErrorNoExcelData, 'No Excel data found in file', # 2
87 ErrorFileEncrypted, 'File is encrypted', # 3
88
89);
90
91
92116µsour %ProcTbl = (
93
94 #Develpers' Kit P291
95 0x14 => \&_subHeader, # Header
96 0x15 => \&_subFooter, # Footer
97 0x18 => \&_subName, # NAME(?)
98 0x1A => \&_subVPageBreak, # Vertical Page Break
99 0x1B => \&_subHPageBreak, # Horizontal Page Break
100 0x22 => \&_subFlg1904, # 1904 Flag
101 0x26 => \&_subMargin, # Left Margin
102 0x27 => \&_subMargin, # Right Margin
103 0x28 => \&_subMargin, # Top Margin
104 0x29 => \&_subMargin, # Bottom Margin
105 0x2A => \&_subPrintHeaders, # Print Headers
106 0x2B => \&_subPrintGridlines, # Print Gridlines
107 0x3C => \&_subContinue, # Continue
108 0x3D => \&_subWindow1, # Window1
109 0x43 => \&_subXF, # XF for Excel < 4.
110 0x0443 => \&_subXF, # XF for Excel = 4.
111 0x862 => \&_subSheetLayout, # Sheet Layout
112 0x1B8 => \&_subHyperlink, # HYPERLINK
113
114 #Develpers' Kit P292
115 0x55 => \&_subDefColWidth, # Consider
116 0x5C => \&_subWriteAccess, # WRITEACCESS
117 0x7D => \&_subColInfo, # Colinfo
118 0x7E => \&_subRK, # RK
119 0x81 => \&_subWSBOOL, # WSBOOL
120 0x83 => \&_subHcenter, # HCENTER
121 0x84 => \&_subVcenter, # VCENTER
122 0x85 => \&_subBoundSheet, # BoundSheet
123
124 0x92 => \&_subPalette, # Palette, fgp
125
126 0x99 => \&_subStandardWidth, # Standard Col
127
128 #Develpers' Kit P293
129 0xA1 => \&_subSETUP, # SETUP
130 0xBD => \&_subMulRK, # MULRK
131 0xBE => \&_subMulBlank, # MULBLANK
132 0xD6 => \&_subRString, # RString
133
134 #Develpers' Kit P294
135 0xE0 => \&_subXF, # ExTended Format
136 0xE5 => \&_subMergeArea, # MergeArea (Not Documented)
137 0xFC => \&_subSST, # Shared String Table
138 0xFD => \&_subLabelSST, # Label SST
139
140 #Develpers' Kit P295
141 0x201 => \&_subBlank, # Blank
142
143 0x202 => \&_subInteger, # Integer(Not Documented)
144 0x203 => \&_subNumber, # Number
145 0x204 => \&_subLabel, # Label
146 0x205 => \&_subBoolErr, # BoolErr
147 0x207 => \&_subString, # STRING
148 0x208 => \&_subRow, # RowData
149 0x221 => \&_subArray, # Array (Consider)
150 0x225 => \&_subDefaultRowHeight, # Consider
151
152 0x31 => \&_subFont, # Font
153 0x231 => \&_subFont, # Font
154
155 0x27E => \&_subRK, # RK
156 0x41E => \&_subFormat, # Format
157
158 0x06 => \&_subFormula, # Formula
159 0x406 => \&_subFormula, # Formula
160
161 0x009 => \&_subBOF, # BOF(BIFF2)
162 0x209 => \&_subBOF, # BOF(BIFF3)
163 0x409 => \&_subBOF, # BOF(BIFF4)
164 0x809 => \&_subBOF, # BOF(BIFF5-8)
165);
166
167our $BIGENDIAN;
168our $PREFUNC;
169our $_use_perlio;
170
171#------------------------------------------------------------------------------
172# Spreadsheet::ParseExcel->new
173#------------------------------------------------------------------------------
174sub new {
175 my ( $class, %hParam ) = @_;
176
177 if ( not defined $_use_perlio ) {
178 if ( exists $Config{useperlio}
179 && defined $Config{useperlio}
180 && $Config{useperlio} eq "define" )
181 {
182 $_use_perlio = 1;
183 }
184 else {
185 $_use_perlio = 0;
186 require IO::Scalar;
187 import IO::Scalar;
188 }
189 }
190
191 # Check ENDIAN(Little: Intel etc. BIG: Sparc etc)
192 $BIGENDIAN =
193 ( defined $hParam{Endian} ) ? $hParam{Endian}
19411µs : ( unpack( "H08", pack( "L", 2 ) ) eq '02000000' ) ? 0
# spent 1µs making 1 call to CORE::pack
195 : 1;
196 my $self = {};
197 bless $self, $class;
198
199 $self->{GetContent} = \&_subGetContent;
200
201 if ( $hParam{EventHandlers} ) {
202 $self->SetEventHandlers( $hParam{EventHandlers} );
203 }
204 else {
205 $self->SetEventHandlers( \%ProcTbl );
206 }
207 if ( $hParam{AddHandlers} ) {
208 foreach my $sKey ( keys( %{ $hParam{AddHandlers} } ) ) {
209 $self->SetEventHandler( $sKey, $hParam{AddHandlers}->{$sKey} );
210 }
211 }
212 $self->{CellHandler} = $hParam{CellHandler};
213 $self->{NotSetCell} = $hParam{NotSetCell};
214 $self->{Object} = $hParam{Object};
215
216
217 if ( defined $hParam{Password} ) {
218 $self->{Password} = $hParam{Password};
219 }
220 else {
221 $self->{Password} = 'VelvetSweatshop';
222 }
223
224 $self->{_error_status} = ErrorNone;
225 return $self;
226}
227
228#------------------------------------------------------------------------------
229# Spreadsheet::ParseExcel->SetEventHandler
230#------------------------------------------------------------------------------
231sub SetEventHandler {
232 my ( $self, $key, $sub_ref ) = @_;
233 $self->{FuncTbl}->{$key} = $sub_ref;
234}
235
236#------------------------------------------------------------------------------
237# Spreadsheet::ParseExcel->SetEventHandlers
238#------------------------------------------------------------------------------
239sub SetEventHandlers {
240 my ( $self, $rhTbl ) = @_;
241 $self->{FuncTbl} = undef;
242 foreach my $sKey ( keys %$rhTbl ) {
243 $self->{FuncTbl}->{$sKey} = $rhTbl->{$sKey};
244 }
245}
246
247#------------------------------------------------------------------------------
248# Decryption routines
249# based on sources of gnumeric (ms-biff.c ms-excel-read.c)
250#------------------------------------------------------------------------------
251sub md5state {
252 my ( $md5 ) = @_;
253 my $s = '';
254 for ( my $i = 0 ; $i < 4 ; $i++ ) {
255 my $v = $md5->{_state}[$i];
256 $s .= chr( $v & 0xff );
257 $s .= chr( ( $v >> 8 ) & 0xff );
258 $s .= chr( ( $v >> 16 ) & 0xff );
259 $s .= chr( ( $v >> 24 ) & 0xff );
260 }
261
262 return $s;
263}
264
265sub MakeKey {
266 my ( $block, $key, $valContext ) = @_;
267
268 my $pwarray = "\0" x 64;
269
270 substr( $pwarray, 0, 5 ) = substr( $valContext, 0, 5 );
271
272 substr( $pwarray, 5, 1 ) = chr( $block & 0xff );
273 substr( $pwarray, 6, 1 ) = chr( ( $block >> 8 ) & 0xff );
274 substr( $pwarray, 7, 1 ) = chr( ( $block >> 16 ) & 0xff );
275 substr( $pwarray, 8, 1 ) = chr( ( $block >> 24 ) & 0xff );
276
277 substr( $pwarray, 9, 1 ) = "\x80";
278 substr( $pwarray, 56, 1 ) = "\x48";
279
280 my $md5 = Digest::Perl::MD5->new();
281 $md5->add( $pwarray );
282
283 my $s = md5state( $md5 );
284
285 ${$key} = Crypt::RC4->new( $s );
286}
287
288sub VerifyPassword {
289 my ( $password, $docid, $salt_data, $hashedsalt_data, $valContext ) = @_;
290
291 my $pwarray = "\0" x 64;
292 my $i;
293 my $md5 = Digest::Perl::MD5->new();
294
295 for ( $i = 0 ; $i < length( $password ) ; $i++ ) {
296 my $o = ord( substr( $password, $i, 1 ) );
297 substr( $pwarray, 2 * $i, 1 ) = chr( $o & 0xff );
298 substr( $pwarray, 2 * $i + 1, 1 ) = chr( ( $o >> 8 ) & 0xff );
299 }
300 substr( $pwarray, 2 * $i, 1 ) = chr( 0x80 );
301 substr( $pwarray, 56, 1 ) = chr( ( $i << 4 ) & 0xff );
302
303 $md5->add( $pwarray );
304
305 my $mdContext1 = md5state( $md5 );
306
307 my $offset = 0;
308 my $keyoffset = 0;
309 my $tocopy = 5;
310
311 $md5->reset;
312
313 while ( $offset != 16 ) {
314 if ( ( 64 - $offset ) < 5 ) {
315 $tocopy = 64 - $offset;
316 }
317
318 substr( $pwarray, $offset, $tocopy ) =
319 substr( $mdContext1, $keyoffset, $tocopy );
320
321 $offset += $tocopy;
322
323 if ( $offset == 64 ) {
324 $md5->add( $pwarray );
325 $keyoffset = $tocopy;
326 $tocopy = 5 - $tocopy;
327 $offset = 0;
328 next;
329 }
330
331 $keyoffset = 0;
332 $tocopy = 5;
333 substr( $pwarray, $offset, 16 ) = $docid;
334 $offset += 16;
335 }
336
337 substr( $pwarray, 16, 1 ) = "\x80";
338 substr( $pwarray, 17, 47 ) = "\0" x 47;
339 substr( $pwarray, 56, 1 ) = "\x80";
340 substr( $pwarray, 57, 1 ) = "\x0a";
341
342 $md5->add( $pwarray );
343 ${$valContext} = md5state( $md5 );
344
345 my $key;
346
347 MakeKey( 0, \$key, ${$valContext} );
348
349 my $salt = $key->RC4( $salt_data );
350 my $hashedsalt = $key->RC4( $hashedsalt_data );
351
352 $salt .= "\x80" . "\0" x 47;
353
354 substr( $salt, 56, 1 ) = "\x80";
355
356 $md5->reset;
357 $md5->add( $salt );
358 my $mdContext2 = md5state( $md5 );
359
360 return ( $mdContext2 eq $hashedsalt );
361}
362
363sub SkipBytes {
364 my ( $q, $start, $count ) = @_;
365
366 my $scratch = "\0" x REKEY_BLOCK;
367 my $block;
368
369 $block = int( ( $start + $count ) / REKEY_BLOCK );
370
371 if ( $block != $q->{block} ) {
372 MakeKey( $q->{block} = $block, \$q->{rc4_key}, $q->{md5_ctxt} );
373 $count = ( $start + $count ) % REKEY_BLOCK;
374 }
375
376 $q->{rc4_key}->RC4( substr( $scratch, 0, $count ) );
377
378 return 1;
379}
380
381sub SetDecrypt {
382 my ( $q, $version, $password ) = @_;
383
384 if ( $q->{opcode} != 0x2f ) {
385 return 0;
386 }
387
388 if ( $password eq '' ) {
389 return 0;
390 }
391
392 # TODO old versions decryption
393 #if (version < MS_BIFF_V8 || q->data[0] == 0)
394 # return ms_biff_pre_biff8_query_set_decrypt (q, password);
395
396 if ( $q->{length} != sizeof_BIFF_8_FILEPASS ) {
397 return 0;
398 }
399
400 unless (
401 VerifyPassword(
402 $password,
403 substr( $q->{data}, 6, 16 ),
404 substr( $q->{data}, 22, 16 ),
405 substr( $q->{data}, 38, 16 ),
406 \$q->{md5_ctxt}
407 )
408 )
409 {
410 return 0;
411 }
412
413 $q->{encryption} = MS_BIFF_CRYPTO_RC4;
414 $q->{block} = -1;
415
416 # The first record after FILEPASS seems to be unencrypted
417 $q->{dont_decrypt_next_record} = 1;
418
419 # Pretend to decrypt the entire stream up till this point, it was
420 # encrypted, but do it anyway to keep the rc4 state in sync
421
422 SkipBytes( $q, 0, $q->{streamPos} );
423
424 return 1;
425}
426
427sub InitStream {
428 my ( $stream_data ) = @_;
429 my %q;
430
431 $q{opcode} = 0;
432 $q{length} = 0;
433 $q{data} = '';
434
435 $q{stream} = $stream_data; # data stream
436 $q{streamLen} = length( $stream_data ); # stream length
437 $q{streamPos} = 0; # stream position
438
439 $q{encryption} = 0;
440 $q{xor_key} = '';
441 $q{rc4_key} = '';
442 $q{md5_ctxt} = '';
443 $q{block} = 0;
444 $q{dont_decrypt_next_record} = 0;
445
446 return \%q;
447}
448
449sub QueryNext {
450 my ( $q ) = @_;
451
452 if ( $q->{streamPos} + 4 >= $q->{streamLen} ) {
453 return 0;
454 }
455
456 my $data = substr( $q->{stream}, $q->{streamPos}, 4 );
457
458 ( $q->{opcode}, $q->{length} ) = unpack( 'v2', $data );
459
460 # No biff record should be larger than around 20,000.
461 if ( $q->{length} >= 20000 ) {
462 return 0;
463 }
464
465 if ( $q->{length} > 0 ) {
466 $q->{data} = substr( $q->{stream}, $q->{streamPos} + 4, $q->{length} );
467 }
468 else {
469 $q->{data} = undef;
470 $q->{dont_decrypt_next_record} = 1;
471 }
472
473 if ( $q->{encryption} == MS_BIFF_CRYPTO_RC4 ) {
474 if ( $q->{dont_decrypt_next_record} ) {
475 SkipBytes( $q, $q->{streamPos}, 4 + $q->{length} );
476 $q->{dont_decrypt_next_record} = 0;
477 }
478 else {
479 my $pos = $q->{streamPos};
480 my $data = $q->{data};
481 my $len = $q->{length};
482 my $res = '';
483
484 # Pretend to decrypt header.
485 SkipBytes( $q, $pos, 4 );
486 $pos += 4;
487
488 while ( $q->{block} != int( ( $pos + $len ) / REKEY_BLOCK ) ) {
489 my $step = REKEY_BLOCK - ( $pos % REKEY_BLOCK );
490 $res .= $q->{rc4_key}->RC4( substr( $data, 0, $step ) );
491 $data = substr( $data, $step );
492 $pos += $step;
493 $len -= $step;
494 MakeKey( ++$q->{block}, \$q->{rc4_key}, $q->{md5_ctxt} );
495 }
496
497 $res .= $q->{rc4_key}->RC4( substr( $data, 0, $len ) );
498 $q->{data} = $res;
499 }
500 }
501 elsif ( $q->{encryption} == MS_BIFF_CRYPTO_XOR ) {
502
503 # not implemented
504 return 0;
505 }
506 elsif ( $q->{encryption} == MS_BIFF_CRYPTO_NONE ) {
507
508 }
509
510 $q->{streamPos} += 4 + $q->{length};
511
512 return 1;
513}
514
515###############################################################################
516#
517# Parse()
518#
519# Parse the Excel file and convert it into a tree of objects..
520#
521sub parse {
522
523 my ( $self, $source, $formatter ) = @_;
524
525 my $workbook = Spreadsheet::ParseExcel::Workbook->new();
526 $currentbook = $workbook;
527 $workbook->{SheetCount} = 0;
528 $workbook->{CellHandler} = $self->{CellHandler};
529 $workbook->{NotSetCell} = $self->{NotSetCell};
530 $workbook->{Object} = $self->{Object};
531 $workbook->{aColor} = [ @aColor ];
532
533 my ( $biff_data, $data_length ) = $self->_get_content( $source, $workbook );
534 return undef if not $biff_data;
535
536 if ( $formatter ) {
537 $workbook->{FmtClass} = $formatter;
538 }
539 else {
540 $workbook->{FmtClass} = Spreadsheet::ParseExcel::FmtDefault->new();
541 }
542
543 # Parse the BIFF data.
544 my $stream = InitStream( $biff_data );
545
546 while ( QueryNext( $stream ) ) {
547
548 my $record = $stream->{opcode};
549 my $record_length = $stream->{length};
550
551 my $record_header = $stream->{data};
552
553 # If the file contains a FILEPASS record we assume that it is encrypted
554 # and cannot be parsed.
555 if ( $record == 0x002F ) {
556 unless ( SetDecrypt( $stream, '', $self->{Password} ) ) {
557 $self->{_error_status} = ErrorFileEncrypted;
558 return undef;
559 }
560 }
561
562 # Special case of a formula String with no string.
563 if ( $workbook->{_PrevPos}
564 && ( defined $self->{FuncTbl}->{$record} )
565 && ( $record != 0x207 ) )
566 {
567 my $iPos = $workbook->{_PrevPos};
568 $workbook->{_PrevPos} = undef;
569
570 my ( $row, $col, $format_index ) = @$iPos;
571 _NewCell(
572 $workbook, $row, $col,
573 Kind => 'Formula String',
574 Val => '',
575 FormatNo => $format_index,
576 Format => $workbook->{Format}[$format_index],
577 Numeric => 0,
578 Code => undef,
579 Book => $workbook,
580 );
581 }
582
583 # If the BIFF record matches 0x0*09 then it is a BOF record.
584 # We reset the _skip_chart flag to ensure we check the sheet type.
585 if ( ( $record & 0xF0FF ) == 0x09 ) {
586 $workbook->{_skip_chart} = 0;
587 }
588
589 if ( defined $self->{FuncTbl}->{$record} && !$workbook->{_skip_chart} )
590 {
591 $self->{FuncTbl}->{$record}
592 ->( $workbook, $record, $record_length, $record_header );
593 }
594
595 $PREFUNC = $record if ( $record != 0x3C ); #Not Continue
596
597 last if defined $workbook->{_ParseAbort};
598 }
599
600 foreach my $worksheet (@{$workbook->{Worksheet}} ) {
601 # Install hyperlinks into each cell
602 # Range is undocumented for user; allows reuse of data
603
604 if ($worksheet->{HyperLinks}) {
605 foreach my $link (@{$worksheet->{HyperLinks}}) {
606 for( my $row = $link->[3]; $row <= $link->[4]; $row++ ) {
607 for( my $col = $link->[5]; $col <= $link->[6]; $col++ ) {
608 $worksheet->{Cells}[$row][$col]{Hyperlink} = $link;
609 }
610 }
611 }
612 }
613 }
614 return $workbook;
615}
616
617###############################################################################
618#
619# _get_content()
620#
621# Get the Excel BIFF content from the file or filehandle.
622#
623sub _get_content {
624
625 my ( $self, $source, $workbook ) = @_;
626 my ( $biff_data, $data_length );
627
628 # Reset the error status in case method is called more than once.
629 $self->{_error_status} = ErrorNone;
630
631 my $ref = ref($source);
632
633 if ( $ref ) {
634 if ( $ref eq 'SCALAR' ) {
635
636 # Specified by a scalar buffer.
637 ( $biff_data, $data_length ) = $self->{GetContent}->( $source );
638
639 }
640 elsif ( $ref eq 'ARRAY' ) {
641
642 # Specified by file content
643 $workbook->{File} = undef;
644 my $sData = join( '', @$source );
645 ( $biff_data, $data_length ) = $self->{GetContent}->( \$sData );
646 }
647 else {
648
649 # Assume filehandle
650
651 # For CGI.pm (Light FileHandle)
652 my $sBuff = '';
653 if ( eval { binmode( $source ) } ) {
654 my $sWk;
655
656 while ( read( $source, $sWk, 4096 ) ) {
657 $sBuff .= $sWk;
658 }
659 }
660 else {
661
662 # Assume IO::Wrap or some other filehandle-like OO-only object
663 my $sWk;
664
665 # IO::Wrap does not implement binmode
666 eval { $source->binmode() };
667
668 while ( $source->read( $sWk, 4096 ) ) {
669 $sBuff .= $sWk;
670 }
671 }
672
673 ( $biff_data, $data_length ) = $self->{GetContent}->( \$sBuff );
674
675 }
676 }
677 else {
678
679 # Specified by filename .
680 $workbook->{File} = $source;
681
682 if ( !-e $source ) {
683 $self->{_error_status} = ErrorNoFile;
684 return undef;
685 }
686
687 ( $biff_data, $data_length ) = $self->{GetContent}->( $source );
688 }
689
690 # If the read was successful return the data.
691 if ( $data_length ) {
692 return ( $biff_data, $data_length );
693 }
694 else {
695 $self->{_error_status} = ErrorNoExcelData;
696 return undef;
697 }
698
699}
700
701#------------------------------------------------------------------------------
702# _subGetContent (for Spreadsheet::ParseExcel)
703#------------------------------------------------------------------------------
704sub _subGetContent {
705 my ( $sFile ) = @_;
706
707 my $oOl = OLE::Storage_Lite->new( $sFile );
708 return ( undef, undef ) unless ( $oOl );
709 my @aRes = $oOl->getPpsSearch(
710 [
711 OLE::Storage_Lite::Asc2Ucs( 'Book' ),
712 OLE::Storage_Lite::Asc2Ucs( 'Workbook' )
713 ],
714 1, 1
715 );
716 return ( undef, undef ) if ( $#aRes < 0 );
717
718 #Hack from Herbert
719 if ( $aRes[0]->{Data} ) {
720 return ( $aRes[0]->{Data}, length( $aRes[0]->{Data} ) );
721 }
722
723 #Same as OLE::Storage_Lite
724 my $oIo;
725
726 #1. $sFile is Ref of scalar
727 if ( ref( $sFile ) eq 'SCALAR' ) {
728 if ( $_use_perlio ) {
729 open $oIo, "<", \$sFile;
730 }
731 else {
732 $oIo = IO::Scalar->new;
733 $oIo->open( $sFile );
734 }
735 }
736
737 #2. $sFile is a IO::Handle object
738 elsif ( UNIVERSAL::isa( $sFile, 'IO::Handle' ) ) {
739 $oIo = $sFile;
740 binmode( $oIo );
741 }
742
743 #3. $sFile is a simple filename string
744 elsif ( !ref( $sFile ) ) {
745 $oIo = IO::File->new;
746 $oIo->open( "<$sFile" ) || return undef;
747 binmode( $oIo );
748 }
749 my $sWk;
750 my $sBuff = '';
751
752 while ( $oIo->read( $sWk, 4096 ) ) { #4_096 has no special meanings
753 $sBuff .= $sWk;
754 }
755 $oIo->close();
756
757 #Not Excel file (simple method)
758 return ( undef, undef ) if ( substr( $sBuff, 0, 1 ) ne "\x09" );
759 return ( $sBuff, length( $sBuff ) );
760}
761
762#------------------------------------------------------------------------------
763# _subBOF (for Spreadsheet::ParseExcel) Developers' Kit : P303
764#------------------------------------------------------------------------------
765sub _subBOF {
766 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
767 my ( $iVer, $iDt ) = unpack( "v2", $sWk );
768
769 #Workbook Global
770 if ( $iDt == 0x0005 ) {
771 $oBook->{Version} = unpack( "v", $sWk );
772 $oBook->{BIFFVersion} =
773 ( $oBook->{Version} == verExcel95 ) ? verBIFF5 : verBIFF8;
774 $oBook->{_CurSheet} = undef;
775 $oBook->{_CurSheet_} = -1;
776 }
777
778 #Worksheet or Dialogsheet
779 elsif ( $iDt != 0x0020 ) { #if($iDt == 0x0010)
780 if ( defined $oBook->{_CurSheet_} ) {
781 $oBook->{_CurSheet} = $oBook->{_CurSheet_} + 1;
782 $oBook->{_CurSheet_}++;
783
784 (
785 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{SheetVersion},
786 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{SheetType},
787 )
788 = unpack( "v2", $sWk )
789 if ( length( $sWk ) > 4 );
790 }
791 else {
792 $oBook->{BIFFVersion} = int( $bOp / 0x100 );
793 if ( ( $oBook->{BIFFVersion} == verBIFF2 )
794 || ( $oBook->{BIFFVersion} == verBIFF3 )
795 || ( $oBook->{BIFFVersion} == verBIFF4 ) )
796 {
797 $oBook->{Version} = $oBook->{BIFFVersion};
798 $oBook->{_CurSheet} = 0;
799 $oBook->{Worksheet}[ $oBook->{SheetCount} ] =
800 Spreadsheet::ParseExcel::Worksheet->new(
801 _Name => '',
802 Name => '',
803 _Book => $oBook,
804 _SheetNo => $oBook->{SheetCount},
805 );
806 $oBook->{SheetCount}++;
807 }
808 }
809 }
810 else {
811
812 # Set flag to ignore all chart records until we reach another BOF.
813 $oBook->{_skip_chart} = 1;
814 }
815}
816
817#------------------------------------------------------------------------------
818# _subBlank (for Spreadsheet::ParseExcel) DK:P303
819#------------------------------------------------------------------------------
820sub _subBlank {
821 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
822 my ( $iR, $iC, $iF ) = unpack( "v3", $sWk );
823 _NewCell(
824 $oBook, $iR, $iC,
825 Kind => 'BLANK',
826 Val => '',
827 FormatNo => $iF,
828 Format => $oBook->{Format}[$iF],
829 Numeric => 0,
830 Code => undef,
831 Book => $oBook,
832 );
833
834 #2.MaxRow, MaxCol, MinRow, MinCol
835 _SetDimension( $oBook, $iR, $iC, $iC );
836}
837
838#------------------------------------------------------------------------------
839# _subInteger (for Spreadsheet::ParseExcel) Not in DK
840#------------------------------------------------------------------------------
841sub _subInteger {
842 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
843 my ( $iR, $iC, $iF, $sTxt, $sDum );
844
845 ( $iR, $iC, $iF, $sDum, $sTxt ) = unpack( "v3cv", $sWk );
846 _NewCell(
847 $oBook, $iR, $iC,
848 Kind => 'INTEGER',
849 Val => $sTxt,
850 FormatNo => $iF,
851 Format => $oBook->{Format}[$iF],
852 Numeric => 0,
853 Code => undef,
854 Book => $oBook,
855 );
856
857 #2.MaxRow, MaxCol, MinRow, MinCol
858 _SetDimension( $oBook, $iR, $iC, $iC );
859}
860
861#------------------------------------------------------------------------------
862# _subNumber (for Spreadsheet::ParseExcel) : DK: P354
863#------------------------------------------------------------------------------
864sub _subNumber {
865 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
866
867 my ( $iR, $iC, $iF ) = unpack( "v3", $sWk );
868 my $dVal = _convDval( substr( $sWk, 6, 8 ) );
869 _NewCell(
870 $oBook, $iR, $iC,
871 Kind => 'Number',
872 Val => $dVal,
873 FormatNo => $iF,
874 Format => $oBook->{Format}[$iF],
875 Numeric => 1,
876 Code => undef,
877 Book => $oBook,
878 );
879
880 #2.MaxRow, MaxCol, MinRow, MinCol
881 _SetDimension( $oBook, $iR, $iC, $iC );
882}
883
884#------------------------------------------------------------------------------
885# _convDval (for Spreadsheet::ParseExcel)
886#------------------------------------------------------------------------------
887sub _convDval {
888 my ( $sWk ) = @_;
889 return
890 unpack( "d",
891 ( $BIGENDIAN ) ? pack( "c8", reverse( unpack( "c8", $sWk ) ) ) : $sWk );
892}
893
894#------------------------------------------------------------------------------
895# _subRString (for Spreadsheet::ParseExcel) DK:P405
896#------------------------------------------------------------------------------
897sub _subRString {
898 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
899 my ( $iR, $iC, $iF, $iL, $sTxt );
900 ( $iR, $iC, $iF, $iL ) = unpack( "v4", $sWk );
901 $sTxt = substr( $sWk, 8, $iL );
902
903 #Has STRUN
904 if ( length( $sWk ) > ( 8 + $iL ) ) {
905 _NewCell(
906 $oBook, $iR, $iC,
907 Kind => 'RString',
908 Val => $sTxt,
909 FormatNo => $iF,
910 Format => $oBook->{Format}[$iF],
911 Numeric => 0,
912 Code => '_native_', #undef,
913 Book => $oBook,
914 Rich => substr( $sWk, ( 8 + $iL ) + 1 ),
915 );
916 }
917 else {
918 _NewCell(
919 $oBook, $iR, $iC,
920 Kind => 'RString',
921 Val => $sTxt,
922 FormatNo => $iF,
923 Format => $oBook->{Format}[$iF],
924 Numeric => 0,
925 Code => '_native_',
926 Book => $oBook,
927 );
928 }
929
930 #2.MaxRow, MaxCol, MinRow, MinCol
931 _SetDimension( $oBook, $iR, $iC, $iC );
932}
933
934#------------------------------------------------------------------------------
935# _subBoolErr (for Spreadsheet::ParseExcel) DK:P306
936#------------------------------------------------------------------------------
937sub _subBoolErr {
938 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
939 my ( $iR, $iC, $iF ) = unpack( "v3", $sWk );
940 my ( $iVal, $iFlg ) = unpack( "cc", substr( $sWk, 6, 2 ) );
941 my $sTxt = DecodeBoolErr( $iVal, $iFlg );
942
943 _NewCell(
944 $oBook, $iR, $iC,
945 Kind => 'BoolError',
946 Val => $sTxt,
947 FormatNo => $iF,
948 Format => $oBook->{Format}[$iF],
949 Numeric => 0,
950 Code => undef,
951 Book => $oBook,
952 );
953
954 #2.MaxRow, MaxCol, MinRow, MinCol
955 _SetDimension( $oBook, $iR, $iC, $iC );
956}
957
958###############################################################################
959#
960# _subRK()
961#
962# Decode the RK BIFF record.
963#
964sub _subRK {
965
966 my ( $workbook, $biff_number, $length, $data ) = @_;
967
968 my ( $row, $col, $format_index, $rk_number ) = unpack( 'vvvV', $data );
969
970 my $number = _decode_rk_number( $rk_number );
971
972 _NewCell(
973 $workbook, $row, $col,
974 Kind => 'RK',
975 Val => $number,
976 FormatNo => $format_index,
977 Format => $workbook->{Format}->[$format_index],
978 Numeric => 1,
979 Code => undef,
980 Book => $workbook,
981 );
982
983 # Store the max and min row/col values.
984 _SetDimension( $workbook, $row, $col, $col );
985}
986
987#------------------------------------------------------------------------------
988# _subArray (for Spreadsheet::ParseExcel) DK:P297
989#------------------------------------------------------------------------------
990sub _subArray {
991 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
992 my ( $iBR, $iER, $iBC, $iEC ) = unpack( "v2c2", $sWk );
993
994}
995
996#------------------------------------------------------------------------------
997# _subFormula (for Spreadsheet::ParseExcel) DK:P336
998#------------------------------------------------------------------------------
999sub _subFormula {
1000 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1001 my ( $iR, $iC, $iF ) = unpack( "v3", $sWk );
1002
1003 my ( $iFlg ) = unpack( "v", substr( $sWk, 12, 2 ) );
1004 if ( $iFlg == 0xFFFF ) {
1005 my ( $iKind ) = unpack( "c", substr( $sWk, 6, 1 ) );
1006 my ( $iVal ) = unpack( "c", substr( $sWk, 8, 1 ) );
1007
1008 if ( ( $iKind == 1 ) or ( $iKind == 2 ) ) {
1009 my $sTxt =
1010 ( $iKind == 1 )
1011 ? DecodeBoolErr( $iVal, 0 )
1012 : DecodeBoolErr( $iVal, 1 );
1013 _NewCell(
1014 $oBook, $iR, $iC,
1015 Kind => 'Formula Bool',
1016 Val => $sTxt,
1017 FormatNo => $iF,
1018 Format => $oBook->{Format}[$iF],
1019 Numeric => 0,
1020 Code => undef,
1021 Book => $oBook,
1022 );
1023 }
1024 else { # Result (Reserve Only)
1025 $oBook->{_PrevPos} = [ $iR, $iC, $iF ];
1026 }
1027 }
1028 else {
1029 my $dVal = _convDval( substr( $sWk, 6, 8 ) );
1030 _NewCell(
1031 $oBook, $iR, $iC,
1032 Kind => 'Formula Number',
1033 Val => $dVal,
1034 FormatNo => $iF,
1035 Format => $oBook->{Format}[$iF],
1036 Numeric => 1,
1037 Code => undef,
1038 Book => $oBook,
1039 );
1040 }
1041
1042 #2.MaxRow, MaxCol, MinRow, MinCol
1043 _SetDimension( $oBook, $iR, $iC, $iC );
1044}
1045
1046#------------------------------------------------------------------------------
1047# _subString (for Spreadsheet::ParseExcel) DK:P414
1048#------------------------------------------------------------------------------
1049sub _subString {
1050 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1051
1052 #Position (not enough for ARRAY)
1053
1054 my $iPos = $oBook->{_PrevPos};
1055 return undef unless ( $iPos );
1056 $oBook->{_PrevPos} = undef;
1057 my ( $iR, $iC, $iF ) = @$iPos;
1058
1059 my ( $iLen, $sTxt, $sCode );
1060 if ( $oBook->{BIFFVersion} == verBIFF8 ) {
1061 my ( $raBuff, $iLen ) = _convBIFF8String( $oBook, $sWk, 1 );
1062 $sTxt = $raBuff->[0];
1063 $sCode = ( $raBuff->[1] ) ? 'ucs2' : undef;
1064 }
1065 elsif ( $oBook->{BIFFVersion} == verBIFF5 ) {
1066 $sCode = '_native_';
1067 $iLen = unpack( "v", $sWk );
1068 $sTxt = substr( $sWk, 2, $iLen );
1069 }
1070 else {
1071 $sCode = '_native_';
1072 $iLen = unpack( "c", $sWk );
1073 $sTxt = substr( $sWk, 1, $iLen );
1074 }
1075 _NewCell(
1076 $oBook, $iR, $iC,
1077 Kind => 'String',
1078 Val => $sTxt,
1079 FormatNo => $iF,
1080 Format => $oBook->{Format}[$iF],
1081 Numeric => 0,
1082 Code => $sCode,
1083 Book => $oBook,
1084 );
1085
1086 #2.MaxRow, MaxCol, MinRow, MinCol
1087 _SetDimension( $oBook, $iR, $iC, $iC );
1088}
1089
1090#------------------------------------------------------------------------------
1091# _subLabel (for Spreadsheet::ParseExcel) DK:P344
1092#------------------------------------------------------------------------------
1093sub _subLabel {
1094 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1095 my ( $iR, $iC, $iF ) = unpack( "v3", $sWk );
1096 my ( $sLbl, $sCode );
1097
1098 #BIFF8
1099 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1100 my ( $raBuff, $iLen, $iStPos, $iLenS ) =
1101 _convBIFF8String( $oBook, substr( $sWk, 6 ), 1 );
1102 $sLbl = $raBuff->[0];
1103 $sCode = ( $raBuff->[1] ) ? 'ucs2' : undef;
1104 }
1105
1106 #Before BIFF8
1107 else {
1108 $sLbl = substr( $sWk, 8 );
1109 $sCode = '_native_';
1110 }
1111 _NewCell(
1112 $oBook, $iR, $iC,
1113 Kind => 'Label',
1114 Val => $sLbl,
1115 FormatNo => $iF,
1116 Format => $oBook->{Format}[$iF],
1117 Numeric => 0,
1118 Code => $sCode,
1119 Book => $oBook,
1120 );
1121
1122 #2.MaxRow, MaxCol, MinRow, MinCol
1123 _SetDimension( $oBook, $iR, $iC, $iC );
1124}
1125
1126###############################################################################
1127#
1128# _subMulRK()
1129#
1130# Decode the Multiple RK BIFF record.
1131#
1132sub _subMulRK {
1133
1134 my ( $workbook, $biff_number, $length, $data ) = @_;
1135
1136 # JMN: I don't know why this is here.
1137 return if $workbook->{SheetCount} <= 0;
1138
1139 my ( $row, $first_col ) = unpack( "v2", $data );
1140 my $last_col = unpack( "v", substr( $data, length( $data ) - 2, 2 ) );
1141
1142 # Iterate over the RK array and decode the data.
1143 my $pos = 4;
1144 for my $col ( $first_col .. $last_col ) {
1145
1146 my $data = substr( $data, $pos, 6 );
1147 my ( $format_index, $rk_number ) = unpack 'vV', $data;
1148 my $number = _decode_rk_number( $rk_number );
1149
1150 _NewCell(
1151 $workbook, $row, $col,
1152 Kind => 'MulRK',
1153 Val => $number,
1154 FormatNo => $format_index,
1155 Format => $workbook->{Format}->[$format_index],
1156 Numeric => 1,
1157 Code => undef,
1158 Book => $workbook,
1159 );
1160 $pos += 6;
1161 }
1162
1163 # Store the max and min row/col values.
1164 _SetDimension( $workbook, $row, $first_col, $last_col );
1165}
1166
1167#------------------------------------------------------------------------------
1168# _subMulBlank (for Spreadsheet::ParseExcel) DK:P349
1169#------------------------------------------------------------------------------
1170sub _subMulBlank {
1171 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1172 my ( $iR, $iSc ) = unpack( "v2", $sWk );
1173 my $iEc = unpack( "v", substr( $sWk, length( $sWk ) - 2, 2 ) );
1174 my $iPos = 4;
1175 for ( my $iC = $iSc ; $iC <= $iEc ; $iC++ ) {
1176 my $iF = unpack( 'v', substr( $sWk, $iPos, 2 ) );
1177 _NewCell(
1178 $oBook, $iR, $iC,
1179 Kind => 'MulBlank',
1180 Val => '',
1181 FormatNo => $iF,
1182 Format => $oBook->{Format}[$iF],
1183 Numeric => 0,
1184 Code => undef,
1185 Book => $oBook,
1186 );
1187 $iPos += 2;
1188 }
1189
1190 #2.MaxRow, MaxCol, MinRow, MinCol
1191 _SetDimension( $oBook, $iR, $iSc, $iEc );
1192}
1193
1194#------------------------------------------------------------------------------
1195# _subLabelSST (for Spreadsheet::ParseExcel) DK: P345
1196#------------------------------------------------------------------------------
1197sub _subLabelSST {
1198 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1199 my ( $iR, $iC, $iF, $iIdx ) = unpack( 'v3V', $sWk );
1200
1201 _NewCell(
1202 $oBook, $iR, $iC,
1203 Kind => 'PackedIdx',
1204 Val => $oBook->{PkgStr}[$iIdx]->{Text},
1205 FormatNo => $iF,
1206 Format => $oBook->{Format}[$iF],
1207 Numeric => 0,
1208 Code => ( $oBook->{PkgStr}[$iIdx]->{Unicode} ) ? 'ucs2' : undef,
1209 Book => $oBook,
1210 Rich => $oBook->{PkgStr}[$iIdx]->{Rich},
1211 );
1212
1213 #2.MaxRow, MaxCol, MinRow, MinCol
1214 _SetDimension( $oBook, $iR, $iC, $iC );
1215}
1216
1217#------------------------------------------------------------------------------
1218# _subFlg1904 (for Spreadsheet::ParseExcel) DK:P296
1219#------------------------------------------------------------------------------
1220sub _subFlg1904 {
1221 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1222 $oBook->{Flg1904} = unpack( "v", $sWk );
1223}
1224
1225#------------------------------------------------------------------------------
1226# _subRow (for Spreadsheet::ParseExcel) DK:P403
1227#------------------------------------------------------------------------------
1228sub _subRow {
1229 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1230 return undef unless ( defined $oBook->{_CurSheet} );
1231
1232 #0. Get Worksheet info (MaxRow, MaxCol, MinRow, MinCol)
1233 my ( $iR, $iSc, $iEc, $iHght, $undef1, $undef2, $iGr, $iXf ) =
1234 unpack( "v8", $sWk );
1235 $iEc--;
1236
1237 if ( $iGr & 0x20 ) {
1238 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{RowHidden}[$iR] = 1;
1239 }
1240
1241 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{RowHeight}[$iR] = $iHght / 20;
1242
1243 #2.MaxRow, MaxCol, MinRow, MinCol
1244 _SetDimension( $oBook, $iR, $iSc, $iEc );
1245}
1246
1247#------------------------------------------------------------------------------
1248# _SetDimension (for Spreadsheet::ParseExcel)
1249#------------------------------------------------------------------------------
1250sub _SetDimension {
1251 my ( $oBook, $iR, $iSc, $iEc ) = @_;
1252 return undef unless ( defined $oBook->{_CurSheet} );
1253
1254 #2.MaxRow, MaxCol, MinRow, MinCol
1255 #2.1 MinRow
1256 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinRow} = $iR
1257 unless ( defined $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinRow} )
1258 and ( $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinRow} <= $iR );
1259
1260 #2.2 MaxRow
1261 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxRow} = $iR
1262 unless ( defined $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxRow} )
1263 and ( $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxRow} > $iR );
1264
1265 #2.3 MinCol
1266 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinCol} = $iSc
1267 unless ( defined $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinCol} )
1268 and ( $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MinCol} <= $iSc );
1269
1270 #2.4 MaxCol
1271 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxCol} = $iEc
1272 unless ( defined $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxCol} )
1273 and ( $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{MaxCol} > $iEc );
1274
1275}
1276
1277#------------------------------------------------------------------------------
1278# _subDefaultRowHeight (for Spreadsheet::ParseExcel) DK: P318
1279#------------------------------------------------------------------------------
1280sub _subDefaultRowHeight {
1281 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1282 return undef unless ( defined $oBook->{_CurSheet} );
1283
1284 #1. RowHeight
1285 my ( $iDum, $iHght ) = unpack( "v2", $sWk );
1286 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{DefRowHeight} = $iHght / 20;
1287
1288}
1289
1290#------------------------------------------------------------------------------
1291# _subStandardWidth(for Spreadsheet::ParseExcel) DK:P413
1292#------------------------------------------------------------------------------
1293sub _subStandardWidth {
1294 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1295 my $iW = unpack( "v", $sWk );
1296 $oBook->{StandardWidth} = _convert_col_width( $oBook, $iW );
1297}
1298
1299###############################################################################
1300#
1301# _subDefColWidth()
1302#
1303# Read the DEFCOLWIDTH Biff record. This gives the width in terms of chars
1304# and is different from the width in the COLINFO record.
1305#
1306sub _subDefColWidth {
1307
1308 my ( $self, $record, $length, $data ) = @_;
1309
1310 my $width = unpack 'v', $data;
1311
1312 # Adjustment for default Arial 10 width.
1313 $width = 8.43 if $width == 8;
1314
1315 $self->{Worksheet}->[ $self->{_CurSheet} ]->{DefColWidth} = $width;
1316}
1317
1318###############################################################################
1319#
1320# _convert_col_width()
1321#
1322# Converts from the internal Excel column width units to user units seen in the
1323# interface. It is first necessary to convert the internal width to pixels and
1324# then to user units. The conversion is specific to a default font of Arial 10.
1325# TODO, the conversion should be extended to other fonts and sizes.
1326#
1327sub _convert_col_width {
1328
1329 my $self = shift;
1330 my $excel_width = shift;
1331
1332 # Convert from Excel units to pixels (rounded up).
1333 my $pixels = int( 0.5 + $excel_width * 7 / 256 );
1334
1335 # Convert from pixels to user units.
1336 # The conversion is different for columns <= 1 user unit (12 pixels).
1337 my $user_width;
1338 if ( $pixels <= 12 ) {
1339 $user_width = $pixels / 12;
1340 }
1341 else {
1342 $user_width = ( $pixels - 5 ) / 7;
1343 }
1344
1345 # Round up to 2 decimal places.
1346 $user_width = int( $user_width * 100 + 0.5 ) / 100;
1347
1348 return $user_width;
1349}
1350
1351#------------------------------------------------------------------------------
1352# _subColInfo (for Spreadsheet::ParseExcel) DK:P309
1353#------------------------------------------------------------------------------
1354sub _subColInfo {
1355
1356 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1357
1358 return undef unless defined $oBook->{_CurSheet};
1359
1360 my ( $iSc, $iEc, $iW, $iXF, $iGr ) = unpack( "v5", $sWk );
1361
1362 for ( my $i = $iSc ; $i <= $iEc ; $i++ ) {
1363
1364 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{ColWidth}[$i] =
1365 _convert_col_width( $oBook, $iW );
1366
1367 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{ColFmtNo}[$i] = $iXF;
1368
1369 if ( $iGr & 0x01 ) {
1370 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{ColHidden}[$i] = 1;
1371 }
1372 }
1373}
1374
1375#------------------------------------------------------------------------------
1376# _subWindow1 Window information P 273
1377#------------------------------------------------------------------------------
1378sub _subWindow1 {
1379 my ( $workbook, $op, $len, $wk ) = @_;
1380
1381 return if ( $workbook->{BIFFVersion} <= verBIFF4() );
1382
1383 my (
1384 $hpos, $vpos, $width,
1385 $height, $options, $active,
1386 $firsttab, $numselected, $tabbarwidth
1387 ) = unpack( "v9", $wk );
1388
1389 $workbook->{ActiveSheet} = $active;
1390}
1391
1392#------------------------------------------------------------------------------
1393# _subSheetLayout OpenOffice 5.96 (P207)
1394#------------------------------------------------------------------------------
1395sub _subSheetLayout {
1396 my ( $workbook, $op, $len, $wk ) = @_;
1397
1398 my @unused;
1399 (
1400 my $rc,
1401 @unused[ 1 .. 10 ],
1402 @unused[ 11 .. 14 ],
1403 my $color, @unused[ 15, 16 ]
1404 ) = unpack( "vC10C4vC2", $wk );
1405
1406 return unless ( $rc == 0x0862 );
1407
1408 $workbook->{Worksheet}[ $workbook->{_CurSheet} ]->{TabColor} = $color;
1409}
1410
1411#------------------------------------------------------------------------------
1412# _subHyperlink OpenOffice 5.96 (P182)
1413#
1414# Also see: http://msdn.microsoft.com/en-us/library/gg615407(v=office.14).aspx
1415#------------------------------------------------------------------------------
1416
1417# Helper: Extract a GID, returns as text string
1418
1419sub _getguid {
1420 my( $wk ) = @_;
1421 my( $text, $guidl, $guids1, $guids2, @guidb );
1422
1423 ( $guidl, $guids1, $guids2, @guidb[0..7] ) = unpack( 'Vv2C8', $wk );
1424
1425 $text = sprintf( '%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X', $guidl, $guids1, $guids2, @guidb);
1426 return $text;
1427}
1428
1429# Helper: Extract a counted (16-bit) unicode string, returns string,
1430# updates $offset
1431# $zterm == 1 if string is null-terminated.
1432# $bc if length is in bytes (not chars)
1433
1434sub _getustr {
1435 my( $wk, $offset, $zterm, $bc ) = @_;
1436
1437 my $len = unpack( 'V', substr( $wk, $offset ) );
1438 $offset += 4;
1439
1440 if( $bc ) {
1441 $len /= 2;
1442 }
1443 $len -= $zterm;
1444 my $text = join( '', map { chr $_ } unpack( "v$len", substr( $wk, $offset ) ) );
1445 $text =~ s/\0.*\z// if( $zterm );
1446 $_[1] = ( $offset += ($len + $zterm) *2 );
1447 return $text;
1448}
1449
1450# HYPERLINK record
1451
1452sub _subHyperlink {
1453 my ( $workbook, $op, $len, $wk ) = @_;
1454
1455 # REF
1456 my( $srow, $erow, $scol, $ecol ) = unpack( 'v4', $wk );
1457
1458 my $guid = _getguid( substr( $wk, 8 ) );
1459 return unless( $guid eq '79EAC9D0-BAF9-11CE-8C82-00AA004BA90B' );
1460
1461 my( $stmvers, $flags ) = unpack( 'VV', substr( $wk, 24 ) );
1462 return if( $flags & 0x60 || $stmvers != 2 );
1463
1464 my $offset = 32;
1465 my( $desc,$frame, $link, $mark );
1466
1467 if( ($flags & 0x14) == 0x14 ) {
1468 $desc = _getustr( $wk, $offset, 1, 0 );
1469 }
1470
1471 if( $flags & 0x80 ) {
1472 $frame = _getustr( $wk, $offset, 1, 0 );
1473 }
1474
1475 $link = '';
1476 if( $flags & 0x100 ) {
1477 # UNC path
1478 $link = 'file:///' . _getustr( $wk, $offset, 1, 0 );
1479 } elsif( $flags & 0x1 ) {
1480 # Has link (URI)
1481 $guid = _getguid( substr( $wk, $offset ) );
1482 $offset += 16;
1483 if( $guid eq '79EAC9E0-BAF9-11CE-8C82-00AA004BA90B' ) {
1484 # URI
1485 $link = _getustr( $wk, $offset, 1, 1 );
1486 } elsif( $guid eq '00000303-0000-0000-C000-000000000046' ) {
1487 # Local file
1488 $link = 'file:///';
1489 # !($flags & 2) = 'relative path'
1490 if( !($flags & 0x2) ) {
1491 my $file = $workbook->{File};
1492 if( defined $file && length $file ) {
1493 $link .= (fileparse($file))[1];
1494 }
1495 else {
1496 $link .= '%REL%'
1497 }
1498 }
1499 my $dirn = unpack( 'v', substr( $wk, $offset ) );
1500 $offset += 2;
1501 $link .= '..\\' x $dirn;
1502 my $namelen = unpack( 'V', substr( $wk, $offset ) );
1503 $offset += 4;
1504 my $name = unpack( 'Z*', substr( $wk, $offset ) );
1505 $offset += $namelen;
1506 $offset += 24;
1507 my $size = unpack( 'V', substr( $wk, $offset ) );
1508 $offset += 4;
1509 if( $size ) {
1510 my $xlen = unpack( 'V', substr( $wk, $offset ) ) / 2;
1511 $name = join( '', map { chr $_} unpack( "v$xlen", substr( $wk, $offset+4+2) ) );
1512 $offset += $size;
1513 }
1514 $link .= $name;
1515 } else {
1516 return;
1517 }
1518 }
1519
1520 # Text mark (Fragment identifier)
1521 if( $flags & 0x8 ) {
1522 # Cellrefs contain reserved characters, so url-encode
1523 my $fragment = _getustr( $wk, $offset, 1 );
1524 $fragment =~ s/([^\w.~-])/sprintf( '%%%02X', ord( $1 ) )/gems;
1525 $link .= '#' . $fragment;
1526 }
1527
1528 # Update loop at end of parse() if this changes
1529
1530 push @{ $workbook->{Worksheet}[ $workbook->{_CurSheet} ]->{HyperLinks} }, [
1531 $desc, $link, $frame, $srow, $erow, $scol, $ecol ];
1532}
1533
1534#------------------------------------------------------------------------------
1535# _subSST (for Spreadsheet::ParseExcel) DK:P413
1536#------------------------------------------------------------------------------
1537sub _subSST {
1538 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1539 _subStrWk( $oBook, substr( $sWk, 8 ) );
1540}
1541
1542#------------------------------------------------------------------------------
1543# _subContinue (for Spreadsheet::ParseExcel) DK:P311
1544#------------------------------------------------------------------------------
1545sub _subContinue {
1546 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1547
1548 #if(defined $self->{FuncTbl}->{$bOp}) {
1549 # $self->{FuncTbl}->{$PREFUNC}->($oBook, $bOp, $bLen, $sWk);
1550 #}
1551
1552 _subStrWk( $oBook, $sWk, 1 ) if ( $PREFUNC == 0xFC );
1553}
1554
1555#------------------------------------------------------------------------------
1556# _subWriteAccess (for Spreadsheet::ParseExcel) DK:P451
1557#------------------------------------------------------------------------------
1558sub _subWriteAccess {
1559 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1560 return if ( defined $oBook->{_Author} );
1561
1562 #BIFF8
1563 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1564 $oBook->{Author} = _convBIFF8String( $oBook, $sWk );
1565 }
1566
1567 #Before BIFF8
1568 else {
1569 my ( $iLen ) = unpack( "c", $sWk );
1570 $oBook->{Author} =
1571 $oBook->{FmtClass}->TextFmt( substr( $sWk, 1, $iLen ), '_native_' );
1572 }
1573}
1574
1575#------------------------------------------------------------------------------
1576# _convBIFF8String (for Spreadsheet::ParseExcel)
1577#------------------------------------------------------------------------------
1578sub _convBIFF8String {
1579 my ( $oBook, $sWk, $iCnvFlg ) = @_;
1580 my ( $iLen, $iFlg ) = unpack( "vc", $sWk );
1581 my ( $iHigh, $iExt, $iRich ) = ( $iFlg & 0x01, $iFlg & 0x04, $iFlg & 0x08 );
1582 my ( $iStPos, $iExtCnt, $iRichCnt, $sStr );
1583
1584 #2. Rich and Ext
1585 if ( $iRich && $iExt ) {
1586 $iStPos = 9;
1587 ( $iRichCnt, $iExtCnt ) = unpack( 'vV', substr( $sWk, 3, 6 ) );
1588 }
1589 elsif ( $iRich ) { #Only Rich
1590 $iStPos = 5;
1591 $iRichCnt = unpack( 'v', substr( $sWk, 3, 2 ) );
1592 $iExtCnt = 0;
1593 }
1594 elsif ( $iExt ) { #Only Ext
1595 $iStPos = 7;
1596 $iRichCnt = 0;
1597 $iExtCnt = unpack( 'V', substr( $sWk, 3, 4 ) );
1598 }
1599 else { #Nothing Special
1600 $iStPos = 3;
1601 $iExtCnt = 0;
1602 $iRichCnt = 0;
1603 }
1604
1605 #3.Get String
1606 if ( $iHigh ) { #Compressed
1607 $iLen *= 2;
1608 $sStr = substr( $sWk, $iStPos, $iLen );
1609 _SwapForUnicode( \$sStr );
1610 $sStr = $oBook->{FmtClass}->TextFmt( $sStr, 'ucs2' )
1611 unless ( $iCnvFlg );
1612 }
1613 else { #Not Compressed
1614 $sStr = substr( $sWk, $iStPos, $iLen );
1615 $sStr = $oBook->{FmtClass}->TextFmt( $sStr, undef ) unless ( $iCnvFlg );
1616 }
1617
1618 #4. return
1619 if ( wantarray ) {
1620
1621 #4.1 Get Rich and Ext
1622 if ( length( $sWk ) < $iStPos + $iLen + $iRichCnt * 4 + $iExtCnt ) {
1623 return (
1624 [ undef, $iHigh, undef, undef ],
1625 $iStPos + $iLen + $iRichCnt * 4 + $iExtCnt,
1626 $iStPos, $iLen
1627 );
1628 }
1629 else {
1630 return (
1631 [
1632 $sStr,
1633 $iHigh,
1634 substr( $sWk, $iStPos + $iLen, $iRichCnt * 4 ),
1635 substr( $sWk, $iStPos + $iLen + $iRichCnt * 4, $iExtCnt )
1636 ],
1637 $iStPos + $iLen + $iRichCnt * 4 + $iExtCnt,
1638 $iStPos, $iLen
1639 );
1640 }
1641 }
1642 else {
1643 return $sStr;
1644 }
1645}
1646
1647#------------------------------------------------------------------------------
1648# _subXF (for Spreadsheet::ParseExcel) DK:P453
1649#------------------------------------------------------------------------------
1650sub _subXF {
1651 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1652
1653 my ( $iFnt, $iIdx );
1654 my (
1655 $iLock, $iHidden, $iStyle, $i123, $iAlH, $iWrap,
1656 $iAlV, $iJustL, $iRotate, $iInd, $iShrink, $iMerge,
1657 $iReadDir, $iBdrD, $iBdrSL, $iBdrSR, $iBdrST, $iBdrSB,
1658 $iBdrSD, $iBdrCL, $iBdrCR, $iBdrCT, $iBdrCB, $iBdrCD,
1659 $iFillP, $iFillCF, $iFillCB
1660 );
1661
1662
1663 if ( $oBook->{BIFFVersion} == verBIFF4 ) {
1664
1665 # Minimal support for Excel 4. We just get the font and format indices
1666 # so that the cell data value can be formatted.
1667 ( $iFnt, $iIdx, ) = unpack( "CC", $sWk );
1668 }
1669 elsif ( $oBook->{BIFFVersion} == verBIFF8 ) {
1670 my ( $iGen, $iAlign, $iGen2, $iBdr1, $iBdr2, $iBdr3, $iPtn );
1671
1672 ( $iFnt, $iIdx, $iGen, $iAlign, $iGen2, $iBdr1, $iBdr2, $iBdr3, $iPtn )
1673 = unpack( "v7Vv", $sWk );
1674 $iLock = ( $iGen & 0x01 ) ? 1 : 0;
1675 $iHidden = ( $iGen & 0x02 ) ? 1 : 0;
1676 $iStyle = ( $iGen & 0x04 ) ? 1 : 0;
1677 $i123 = ( $iGen & 0x08 ) ? 1 : 0;
1678 $iAlH = ( $iAlign & 0x07 );
1679 $iWrap = ( $iAlign & 0x08 ) ? 1 : 0;
1680 $iAlV = ( $iAlign & 0x70 ) / 0x10;
1681 $iJustL = ( $iAlign & 0x80 ) ? 1 : 0;
1682
1683 $iRotate = ( ( $iAlign & 0xFF00 ) / 0x100 ) & 0x00FF;
1684 $iRotate = 90 if ( $iRotate == 255 );
1685 $iRotate = 90 - $iRotate if ( $iRotate > 90 );
1686
1687 $iInd = ( $iGen2 & 0x0F );
1688 $iShrink = ( $iGen2 & 0x10 ) ? 1 : 0;
1689 $iMerge = ( $iGen2 & 0x20 ) ? 1 : 0;
1690 $iReadDir = ( ( $iGen2 & 0xC0 ) / 0x40 ) & 0x03;
1691 $iBdrSL = $iBdr1 & 0x0F;
1692 $iBdrSR = ( ( $iBdr1 & 0xF0 ) / 0x10 ) & 0x0F;
1693 $iBdrST = ( ( $iBdr1 & 0xF00 ) / 0x100 ) & 0x0F;
1694 $iBdrSB = ( ( $iBdr1 & 0xF000 ) / 0x1000 ) & 0x0F;
1695
1696 $iBdrCL = ( ( $iBdr2 & 0x7F ) ) & 0x7F;
1697 $iBdrCR = ( ( $iBdr2 & 0x3F80 ) / 0x80 ) & 0x7F;
1698 $iBdrD = ( ( $iBdr2 & 0xC000 ) / 0x4000 ) & 0x3;
1699
1700 $iBdrCT = ( ( $iBdr3 & 0x7F ) ) & 0x7F;
1701 $iBdrCB = ( ( $iBdr3 & 0x3F80 ) / 0x80 ) & 0x7F;
1702 $iBdrCD = ( ( $iBdr3 & 0x1FC000 ) / 0x4000 ) & 0x7F;
1703 $iBdrSD = ( ( $iBdr3 & 0x1E00000 ) / 0x200000 ) & 0xF;
1704 $iFillP = ( ( $iBdr3 & 0xFC000000 ) / 0x4000000 ) & 0x3F;
1705
1706 $iFillCF = ( $iPtn & 0x7F );
1707 $iFillCB = ( ( $iPtn & 0x3F80 ) / 0x80 ) & 0x7F;
1708 }
1709 else {
1710 my ( $iGen, $iAlign, $iPtn, $iPtn2, $iBdr1, $iBdr2 );
1711
1712 ( $iFnt, $iIdx, $iGen, $iAlign, $iPtn, $iPtn2, $iBdr1, $iBdr2 ) =
1713 unpack( "v8", $sWk );
1714 $iLock = ( $iGen & 0x01 ) ? 1 : 0;
1715 $iHidden = ( $iGen & 0x02 ) ? 1 : 0;
1716 $iStyle = ( $iGen & 0x04 ) ? 1 : 0;
1717 $i123 = ( $iGen & 0x08 ) ? 1 : 0;
1718
1719 $iAlH = ( $iAlign & 0x07 );
1720 $iWrap = ( $iAlign & 0x08 ) ? 1 : 0;
1721 $iAlV = ( $iAlign & 0x70 ) / 0x10;
1722 $iJustL = ( $iAlign & 0x80 ) ? 1 : 0;
1723
1724 $iRotate = ( ( $iAlign & 0x300 ) / 0x100 ) & 0x3;
1725
1726 $iFillCF = ( $iPtn & 0x7F );
1727 $iFillCB = ( ( $iPtn & 0x1F80 ) / 0x80 ) & 0x7F;
1728
1729 $iFillP = ( $iPtn2 & 0x3F );
1730 $iBdrSB = ( ( $iPtn2 & 0x1C0 ) / 0x40 ) & 0x7;
1731 $iBdrCB = ( ( $iPtn2 & 0xFE00 ) / 0x200 ) & 0x7F;
1732
1733 $iBdrST = ( $iBdr1 & 0x07 );
1734 $iBdrSL = ( ( $iBdr1 & 0x38 ) / 0x8 ) & 0x07;
1735 $iBdrSR = ( ( $iBdr1 & 0x1C0 ) / 0x40 ) & 0x07;
1736 $iBdrCT = ( ( $iBdr1 & 0xFE00 ) / 0x200 ) & 0x7F;
1737
1738 $iBdrCL = ( $iBdr2 & 0x7F ) & 0x7F;
1739 $iBdrCR = ( ( $iBdr2 & 0x3F80 ) / 0x80 ) & 0x7F;
1740 }
1741
1742 push @{ $oBook->{Format} }, Spreadsheet::ParseExcel::Format->new(
1743 FontNo => $iFnt,
1744 Font => $oBook->{Font}[$iFnt],
1745 FmtIdx => $iIdx,
1746
1747 Lock => $iLock,
1748 Hidden => $iHidden,
1749 Style => $iStyle,
1750 Key123 => $i123,
1751 AlignH => $iAlH,
1752 Wrap => $iWrap,
1753 AlignV => $iAlV,
1754 JustLast => $iJustL,
1755 Rotate => $iRotate,
1756
1757 Indent => $iInd,
1758 Shrink => $iShrink,
1759 Merge => $iMerge,
1760 ReadDir => $iReadDir,
1761
1762 BdrStyle => [ $iBdrSL, $iBdrSR, $iBdrST, $iBdrSB ],
1763 BdrColor => [ $iBdrCL, $iBdrCR, $iBdrCT, $iBdrCB ],
1764 BdrDiag => [ $iBdrD, $iBdrSD, $iBdrCD ],
1765 Fill => [ $iFillP, $iFillCF, $iFillCB ],
1766 );
1767}
1768
1769#------------------------------------------------------------------------------
1770# _subFormat (for Spreadsheet::ParseExcel) DK: P336
1771#------------------------------------------------------------------------------
1772sub _subFormat {
1773
1774 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1775 my $sFmt;
1776
1777 if ( $oBook->{BIFFVersion} <= verBIFF5 ) {
1778 $sFmt = substr( $sWk, 3, unpack( 'c', substr( $sWk, 2, 1 ) ) );
1779 $sFmt = $oBook->{FmtClass}->TextFmt( $sFmt, '_native_' );
1780 }
1781 else {
1782 $sFmt = _convBIFF8String( $oBook, substr( $sWk, 2 ) );
1783 }
1784
1785 my $format_index = unpack( 'v', substr( $sWk, 0, 2 ) );
1786
1787 # Excel 4 and earlier used an index of 0 to indicate that a built-in format
1788 # that was stored implicitly.
1789 if ( $oBook->{BIFFVersion} <= verBIFF4 && $format_index == 0 ) {
1790 $format_index = keys %{ $oBook->{FormatStr} };
1791 }
1792
1793 $oBook->{FormatStr}->{$format_index} = $sFmt;
1794}
1795
1796#------------------------------------------------------------------------------
1797# _subPalette (for Spreadsheet::ParseExcel) DK: P393
1798#------------------------------------------------------------------------------
1799sub _subPalette {
1800 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1801 for ( my $i = 0 ; $i < unpack( 'v', $sWk ) ; $i++ ) {
1802
1803 # push @aColor, unpack('H6', substr($sWk, $i*4+2));
1804 $oBook->{aColor}[ $i + 8 ] = unpack( 'H6', substr( $sWk, $i * 4 + 2 ) );
1805 }
1806}
1807
1808#------------------------------------------------------------------------------
1809# _subFont (for Spreadsheet::ParseExcel) DK:P333
1810#------------------------------------------------------------------------------
1811sub _subFont {
1812 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1813 my ( $iHeight, $iAttr, $iCIdx, $iBold, $iSuper, $iUnderline, $sFntName );
1814 my ( $bBold, $bItalic, $bUnderline, $bStrikeout );
1815
1816 if ( $oBook->{BIFFVersion} == verBIFF8 ) {
1817 ( $iHeight, $iAttr, $iCIdx, $iBold, $iSuper, $iUnderline ) =
1818 unpack( "v5c", $sWk );
1819 my ( $iSize, $iHigh ) = unpack( 'cc', substr( $sWk, 14, 2 ) );
1820 if ( $iHigh ) {
1821 $sFntName = substr( $sWk, 16, $iSize * 2 );
1822 _SwapForUnicode( \$sFntName );
1823 $sFntName = $oBook->{FmtClass}->TextFmt( $sFntName, 'ucs2' );
1824 }
1825 else {
1826 $sFntName = substr( $sWk, 16, $iSize );
1827 $sFntName = $oBook->{FmtClass}->TextFmt( $sFntName, '_native_' );
1828 }
1829 $bBold = ( $iBold >= 0x2BC ) ? 1 : 0;
1830 $bItalic = ( $iAttr & 0x02 ) ? 1 : 0;
1831 $bStrikeout = ( $iAttr & 0x08 ) ? 1 : 0;
1832 $bUnderline = ( $iUnderline ) ? 1 : 0;
1833 }
1834 elsif ( $oBook->{BIFFVersion} == verBIFF5 ) {
1835 ( $iHeight, $iAttr, $iCIdx, $iBold, $iSuper, $iUnderline ) =
1836 unpack( "v5c", $sWk );
1837 $sFntName =
1838 $oBook->{FmtClass}
1839 ->TextFmt( substr( $sWk, 15, unpack( "c", substr( $sWk, 14, 1 ) ) ),
1840 '_native_' );
1841 $bBold = ( $iBold >= 0x2BC ) ? 1 : 0;
1842 $bItalic = ( $iAttr & 0x02 ) ? 1 : 0;
1843 $bStrikeout = ( $iAttr & 0x08 ) ? 1 : 0;
1844 $bUnderline = ( $iUnderline ) ? 1 : 0;
1845 }
1846 else {
1847 ( $iHeight, $iAttr ) = unpack( "v2", $sWk );
1848 $iCIdx = undef;
1849 $iSuper = 0;
1850
1851 $bBold = ( $iAttr & 0x01 ) ? 1 : 0;
1852 $bItalic = ( $iAttr & 0x02 ) ? 1 : 0;
1853 $bUnderline = ( $iAttr & 0x04 ) ? 1 : 0;
1854 $bStrikeout = ( $iAttr & 0x08 ) ? 1 : 0;
1855
1856 $sFntName = substr( $sWk, 5, unpack( "c", substr( $sWk, 4, 1 ) ) );
1857 }
1858 push @{ $oBook->{Font} }, Spreadsheet::ParseExcel::Font->new(
1859 Height => $iHeight / 20.0,
1860 Attr => $iAttr,
1861 Color => $iCIdx,
1862 Super => $iSuper,
1863 UnderlineStyle => $iUnderline,
1864 Name => $sFntName,
1865
1866 Bold => $bBold,
1867 Italic => $bItalic,
1868 Underline => $bUnderline,
1869 Strikeout => $bStrikeout,
1870 );
1871
1872 #Skip Font[4]
1873 push @{ $oBook->{Font} }, {} if ( scalar( @{ $oBook->{Font} } ) == 4 );
1874
1875}
1876
1877#------------------------------------------------------------------------------
1878# _subBoundSheet (for Spreadsheet::ParseExcel): DK: P307
1879#------------------------------------------------------------------------------
1880sub _subBoundSheet {
1881 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1882 my ( $iPos, $iGr, $iKind ) = unpack( "Lc2", $sWk );
1883 $iKind &= 0x0F;
1884 return if ( ( $iKind != 0x00 ) && ( $iKind != 0x01 ) );
1885
1886 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1887 my ( $iSize, $iUni ) = unpack( "cc", substr( $sWk, 6, 2 ) );
1888 my $sWsName = substr( $sWk, 8 );
1889 if ( $iUni & 0x01 ) {
1890 _SwapForUnicode( \$sWsName );
1891 $sWsName = $oBook->{FmtClass}->TextFmt( $sWsName, 'ucs2' );
1892 }
1893 $oBook->{Worksheet}[ $oBook->{SheetCount} ] =
1894 Spreadsheet::ParseExcel::Worksheet->new(
1895 Name => $sWsName,
1896 Kind => $iKind,
1897 _Pos => $iPos,
1898 _Book => $oBook,
1899 _SheetNo => $oBook->{SheetCount},
1900 SheetHidden => $iGr & 0x03
1901 );
1902 }
1903 else {
1904 $oBook->{Worksheet}[ $oBook->{SheetCount} ] =
1905 Spreadsheet::ParseExcel::Worksheet->new(
1906 Name =>
1907 $oBook->{FmtClass}->TextFmt( substr( $sWk, 7 ), '_native_' ),
1908 Kind => $iKind,
1909 _Pos => $iPos,
1910 _Book => $oBook,
1911 _SheetNo => $oBook->{SheetCount},
1912 SheetHidden => $iGr & 0x03
1913 );
1914 }
1915 $oBook->{SheetCount}++;
1916}
1917
1918#------------------------------------------------------------------------------
1919# _subHeader (for Spreadsheet::ParseExcel) DK: P340
1920#------------------------------------------------------------------------------
1921sub _subHeader {
1922 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1923 return undef unless ( defined $oBook->{_CurSheet} );
1924 my $sW;
1925
1926 if ( !defined $sWk ) {
1927 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Header} = undef;
1928 return;
1929 }
1930
1931 #BIFF8
1932 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1933 $sW = _convBIFF8String( $oBook, $sWk );
1934 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Header} =
1935 ( $sW eq "\x00" ) ? undef : $sW;
1936 }
1937
1938 #Before BIFF8
1939 else {
1940 my ( $iLen ) = unpack( "c", $sWk );
1941 $sW =
1942 $oBook->{FmtClass}->TextFmt( substr( $sWk, 1, $iLen ), '_native_' );
1943 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Header} =
1944 ( $sW eq "\x00\x00\x00" ) ? undef : $sW;
1945 }
1946}
1947
1948#------------------------------------------------------------------------------
1949# _subFooter (for Spreadsheet::ParseExcel) DK: P335
1950#------------------------------------------------------------------------------
1951sub _subFooter {
1952 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1953 return undef unless ( defined $oBook->{_CurSheet} );
1954 my $sW;
1955
1956 if ( !defined $sWk ) {
1957 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Footer} = undef;
1958 return;
1959 }
1960
1961 #BIFF8
1962 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1963 $sW = _convBIFF8String( $oBook, $sWk );
1964 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Footer} =
1965 ( $sW eq "\x00" ) ? undef : $sW;
1966 }
1967
1968 #Before BIFF8
1969 else {
1970 my ( $iLen ) = unpack( "c", $sWk );
1971 $sW =
1972 $oBook->{FmtClass}->TextFmt( substr( $sWk, 1, $iLen ), '_native_' );
1973 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Footer} =
1974 ( $sW eq "\x00\x00\x00" ) ? undef : $sW;
1975 }
1976}
1977
1978#------------------------------------------------------------------------------
1979# _subHPageBreak (for Spreadsheet::ParseExcel) DK: P341
1980#------------------------------------------------------------------------------
1981sub _subHPageBreak {
1982 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
1983 my @aBreak;
1984 my $iCnt = unpack( "v", $sWk );
1985
1986 return undef unless ( defined $oBook->{_CurSheet} );
1987
1988 #BIFF8
1989 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
1990 for ( my $i = 0 ; $i < $iCnt ; $i++ ) {
1991 my ( $iRow, $iColB, $iColE ) =
1992 unpack( 'v3', substr( $sWk, 2 + $i * 6, 6 ) );
1993
1994 # push @aBreak, [$iRow, $iColB, $iColE];
1995 push @aBreak, $iRow;
1996 }
1997 }
1998
1999 #Before BIFF8
2000 else {
2001 for ( my $i = 0 ; $i < $iCnt ; $i++ ) {
2002 my ( $iRow ) = unpack( 'v', substr( $sWk, 2 + $i * 2, 2 ) );
2003 push @aBreak, $iRow;
2004
2005 # push @aBreak, [$iRow, 0, 255];
2006 }
2007 }
2008 @aBreak = sort { $a <=> $b } @aBreak;
2009 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{HPageBreak} = \@aBreak;
2010}
2011
2012#------------------------------------------------------------------------------
2013# _subVPageBreak (for Spreadsheet::ParseExcel) DK: P447
2014#------------------------------------------------------------------------------
2015sub _subVPageBreak {
2016 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2017 return undef unless ( defined $oBook->{_CurSheet} );
2018
2019 my @aBreak;
2020 my $iCnt = unpack( "v", $sWk );
2021
2022 #BIFF8
2023 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
2024 for ( my $i = 0 ; $i < $iCnt ; $i++ ) {
2025 my ( $iCol, $iRowB, $iRowE ) =
2026 unpack( 'v3', substr( $sWk, 2 + $i * 6, 6 ) );
2027 push @aBreak, $iCol;
2028
2029 # push @aBreak, [$iCol, $iRowB, $iRowE];
2030 }
2031 }
2032
2033 #Before BIFF8
2034 else {
2035 for ( my $i = 0 ; $i < $iCnt ; $i++ ) {
2036 my ( $iCol ) = unpack( 'v', substr( $sWk, 2 + $i * 2, 2 ) );
2037 push @aBreak, $iCol;
2038
2039 # push @aBreak, [$iCol, 0, 65535];
2040 }
2041 }
2042 @aBreak = sort { $a <=> $b } @aBreak;
2043 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{VPageBreak} = \@aBreak;
2044}
2045
2046#------------------------------------------------------------------------------
2047# _subMargin (for Spreadsheet::ParseExcel) DK: P306, 345, 400, 440
2048#------------------------------------------------------------------------------
2049sub _subMargin {
2050 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2051 return undef unless ( defined $oBook->{_CurSheet} );
2052
2053 # The "Mergin" options are a workaround for a backward compatible typo.
2054
2055 my $dWk = _convDval( substr( $sWk, 0, 8 ) );
2056 if ( $bOp == 0x26 ) {
2057 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{LeftMergin} = $dWk;
2058 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{LeftMargin} = $dWk;
2059 }
2060 elsif ( $bOp == 0x27 ) {
2061 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{RightMergin} = $dWk;
2062 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{RightMargin} = $dWk;
2063 }
2064 elsif ( $bOp == 0x28 ) {
2065 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{TopMergin} = $dWk;
2066 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{TopMargin} = $dWk;
2067 }
2068 elsif ( $bOp == 0x29 ) {
2069 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{BottomMergin} = $dWk;
2070 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{BottomMargin} = $dWk;
2071 }
2072}
2073
2074#------------------------------------------------------------------------------
2075# _subHcenter (for Spreadsheet::ParseExcel) DK: P340
2076#------------------------------------------------------------------------------
2077sub _subHcenter {
2078 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2079 return undef unless ( defined $oBook->{_CurSheet} );
2080
2081 my $iWk = unpack( "v", $sWk );
2082 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{HCenter} = $iWk;
2083
2084}
2085
2086#------------------------------------------------------------------------------
2087# _subVcenter (for Spreadsheet::ParseExcel) DK: P447
2088#------------------------------------------------------------------------------
2089sub _subVcenter {
2090 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2091 return undef unless ( defined $oBook->{_CurSheet} );
2092
2093 my $iWk = unpack( "v", $sWk );
2094 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{VCenter} = $iWk;
2095}
2096
2097#------------------------------------------------------------------------------
2098# _subPrintGridlines (for Spreadsheet::ParseExcel) DK: P397
2099#------------------------------------------------------------------------------
2100sub _subPrintGridlines {
2101 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2102 return undef unless ( defined $oBook->{_CurSheet} );
2103
2104 my $iWk = unpack( "v", $sWk );
2105 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{PrintGrid} = $iWk;
2106
2107}
2108
2109#------------------------------------------------------------------------------
2110# _subPrintHeaders (for Spreadsheet::ParseExcel) DK: P397
2111#------------------------------------------------------------------------------
2112sub _subPrintHeaders {
2113 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2114 return undef unless ( defined $oBook->{_CurSheet} );
2115
2116 my $iWk = unpack( "v", $sWk );
2117 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{PrintHeaders} = $iWk;
2118}
2119
2120#------------------------------------------------------------------------------
2121# _subSETUP (for Spreadsheet::ParseExcel) DK: P409
2122#------------------------------------------------------------------------------
2123sub _subSETUP {
2124 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2125 return undef unless ( defined $oBook->{_CurSheet} );
2126
2127 # Workaround for some apps and older Excels that don't write a
2128 # complete SETUP record.
2129 return undef if $bLen != 34;
2130
2131 my $oWkS = $oBook->{Worksheet}[ $oBook->{_CurSheet} ];
2132 my $iGrBit;
2133
2134 (
2135 $oWkS->{PaperSize}, $oWkS->{Scale}, $oWkS->{PageStart},
2136 $oWkS->{FitWidth}, $oWkS->{FitHeight}, $iGrBit,
2137 $oWkS->{Res}, $oWkS->{VRes},
2138 ) = unpack( 'v8', $sWk );
2139
2140 $oWkS->{HeaderMargin} = _convDval( substr( $sWk, 16, 8 ) );
2141 $oWkS->{FooterMargin} = _convDval( substr( $sWk, 24, 8 ) );
2142 $oWkS->{Copis} = unpack( 'v2', substr( $sWk, 32, 2 ) );
2143 $oWkS->{LeftToRight} = ( ( $iGrBit & 0x01 ) ? 1 : 0 );
2144 $oWkS->{Landscape} = ( ( $iGrBit & 0x02 ) ? 1 : 0 );
2145 $oWkS->{NoPls} = ( ( $iGrBit & 0x04 ) ? 1 : 0 );
2146 $oWkS->{NoColor} = ( ( $iGrBit & 0x08 ) ? 1 : 0 );
2147 $oWkS->{Draft} = ( ( $iGrBit & 0x10 ) ? 1 : 0 );
2148 $oWkS->{Notes} = ( ( $iGrBit & 0x20 ) ? 1 : 0 );
2149 $oWkS->{NoOrient} = ( ( $iGrBit & 0x40 ) ? 1 : 0 );
2150 $oWkS->{UsePage} = ( ( $iGrBit & 0x80 ) ? 1 : 0 );
2151
2152 # The NoPls flag indicates that the values have not been taken from an
2153 # actual printer and thus may not be accurate.
2154
2155 # Set default scale if NoPls otherwise it may be an invalid value of 0XFF.
2156 $oWkS->{Scale} = 100 if $oWkS->{NoPls};
2157
2158 # Workaround for a backward compatible typo.
2159 $oWkS->{HeaderMergin} = $oWkS->{HeaderMargin};
2160 $oWkS->{FooterMergin} = $oWkS->{FooterMargin};
2161
2162}
2163
2164#------------------------------------------------------------------------------
2165# _subName (for Spreadsheet::ParseExcel) DK: P350
2166#------------------------------------------------------------------------------
2167sub _subName {
2168 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2169 my (
2170 $iGrBit, $cKey, $cCh, $iCce, $ixAls,
2171 $iTab, $cchCust, $cchDsc, $cchHep, $cchStatus
2172 ) = unpack( 'vc2v3c4', $sWk );
2173
2174 #Builtin Name + Length == 1
2175 if ( ( $iGrBit & 0x20 ) && ( $cCh == 1 ) ) {
2176
2177 #BIFF8
2178 if ( $oBook->{BIFFVersion} >= verBIFF8 ) {
2179 my $iName = unpack( 'n', substr( $sWk, 14 ) );
2180 my $iSheet = unpack( 'v', substr( $sWk, 8 ) ) - 1;
2181
2182 # Workaround for mal-formed Excel workbooks where Print_Title is
2183 # set as Global (i.e. itab = 0). Note, this will have to be
2184 # treated differently when we get around to handling global names.
2185 return undef if $iSheet == -1;
2186
2187 if ( $iName == 6 ) { #PrintArea
2188 my ( $iSheetW, $raArea ) = _ParseNameArea( substr( $sWk, 16 ) );
2189 $oBook->{PrintArea}[$iSheet] = $raArea;
2190 }
2191 elsif ( $iName == 7 ) { #Title
2192 my ( $iSheetW, $raArea ) = _ParseNameArea( substr( $sWk, 16 ) );
2193 my @aTtlR = ();
2194 my @aTtlC = ();
2195 foreach my $raI ( @$raArea ) {
2196 if ( $raI->[3] == 0xFF ) { #Row Title
2197 push @aTtlR, [ $raI->[0], $raI->[2] ];
2198 }
2199 else { #Col Title
2200 push @aTtlC, [ $raI->[1], $raI->[3] ];
2201 }
2202 }
2203 $oBook->{PrintTitle}[$iSheet] =
2204 { Row => \@aTtlR, Column => \@aTtlC };
2205 }
2206 }
2207 else {
2208 my $iName = unpack( 'c', substr( $sWk, 14 ) );
2209 if ( $iName == 6 ) { #PrintArea
2210 my ( $iSheet, $raArea ) =
2211 _ParseNameArea95( substr( $sWk, 15 ) );
2212 $oBook->{PrintArea}[$iSheet] = $raArea;
2213 }
2214 elsif ( $iName == 7 ) { #Title
2215 my ( $iSheet, $raArea ) =
2216 _ParseNameArea95( substr( $sWk, 15 ) );
2217 my @aTtlR = ();
2218 my @aTtlC = ();
2219 foreach my $raI ( @$raArea ) {
2220 if ( $raI->[3] == 0xFF ) { #Row Title
2221 push @aTtlR, [ $raI->[0], $raI->[2] ];
2222 }
2223 else { #Col Title
2224 push @aTtlC, [ $raI->[1], $raI->[3] ];
2225 }
2226 }
2227 $oBook->{PrintTitle}[$iSheet] =
2228 { Row => \@aTtlR, Column => \@aTtlC };
2229 }
2230 }
2231 }
2232}
2233
2234#------------------------------------------------------------------------------
2235# ParseNameArea (for Spreadsheet::ParseExcel) DK: 494 (ptgAread3d)
2236#------------------------------------------------------------------------------
2237sub _ParseNameArea {
2238 my ( $sObj ) = @_;
2239 my ( $iOp );
2240 my @aRes = ();
2241 $iOp = unpack( 'C', $sObj );
2242 my $iSheet;
2243 if ( $iOp == 0x3b ) {
2244 my ( $iWkS, $iRs, $iRe, $iCs, $iCe ) =
2245 unpack( 'v5', substr( $sObj, 1 ) );
2246 $iSheet = $iWkS;
2247 push @aRes, [ $iRs, $iCs, $iRe, $iCe ];
2248 }
2249 elsif ( $iOp == 0x29 ) {
2250 my $iLen = unpack( 'v', substr( $sObj, 1, 2 ) );
2251 my $iSt = 0;
2252 while ( $iSt < $iLen ) {
2253 my ( $iOpW, $iWkS, $iRs, $iRe, $iCs, $iCe ) =
2254 unpack( 'cv5', substr( $sObj, $iSt + 3, 11 ) );
2255
2256 if ( $iOpW == 0x3b ) {
2257 $iSheet = $iWkS;
2258 push @aRes, [ $iRs, $iCs, $iRe, $iCe ];
2259 }
2260
2261 if ( $iSt == 0 ) {
2262 $iSt += 11;
2263 }
2264 else {
2265 $iSt += 12; #Skip 1 byte;
2266 }
2267 }
2268 }
2269 return ( $iSheet, \@aRes );
2270}
2271
2272#------------------------------------------------------------------------------
2273# ParseNameArea95 (for Spreadsheet::ParseExcel) DK: 494 (ptgAread3d)
2274#------------------------------------------------------------------------------
2275sub _ParseNameArea95 {
2276 my ( $sObj ) = @_;
2277 my ( $iOp );
2278 my @aRes = ();
2279 $iOp = unpack( 'C', $sObj );
2280 my $iSheet;
2281 if ( $iOp == 0x3b ) {
2282 $iSheet = unpack( 'v', substr( $sObj, 11, 2 ) );
2283 my ( $iRs, $iRe, $iCs, $iCe ) =
2284 unpack( 'v2C2', substr( $sObj, 15, 6 ) );
2285 push @aRes, [ $iRs, $iCs, $iRe, $iCe ];
2286 }
2287 elsif ( $iOp == 0x29 ) {
2288 my $iLen = unpack( 'v', substr( $sObj, 1, 2 ) );
2289 my $iSt = 0;
2290 while ( $iSt < $iLen ) {
2291 my $iOpW = unpack( 'c', substr( $sObj, $iSt + 3, 6 ) );
2292 $iSheet = unpack( 'v', substr( $sObj, $iSt + 14, 2 ) );
2293 my ( $iRs, $iRe, $iCs, $iCe ) =
2294 unpack( 'v2C2', substr( $sObj, $iSt + 18, 6 ) );
2295 push @aRes, [ $iRs, $iCs, $iRe, $iCe ] if ( $iOpW == 0x3b );
2296
2297 if ( $iSt == 0 ) {
2298 $iSt += 21;
2299 }
2300 else {
2301 $iSt += 22; #Skip 1 byte;
2302 }
2303 }
2304 }
2305 return ( $iSheet, \@aRes );
2306}
2307
2308#------------------------------------------------------------------------------
2309# _subBOOL (for Spreadsheet::ParseExcel) DK: P452
2310#------------------------------------------------------------------------------
2311sub _subWSBOOL {
2312 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2313 return undef unless ( defined $oBook->{_CurSheet} );
2314
2315 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{PageFit} =
2316 ( ( unpack( 'v', $sWk ) & 0x100 ) ? 1 : 0 );
2317}
2318
2319#------------------------------------------------------------------------------
2320# _subMergeArea (for Spreadsheet::ParseExcel) DK: (Not)
2321#------------------------------------------------------------------------------
2322sub _subMergeArea {
2323 my ( $oBook, $bOp, $bLen, $sWk ) = @_;
2324 return undef unless ( defined $oBook->{_CurSheet} );
2325
2326 my $iCnt = unpack( "v", $sWk );
2327 my $oWkS = $oBook->{Worksheet}[ $oBook->{_CurSheet} ];
2328 $oWkS->{MergedArea} = [] unless ( defined $oWkS->{MergedArea} );
2329 for ( my $i = 0 ; $i < $iCnt ; $i++ ) {
2330 my ( $iRs, $iRe, $iCs, $iCe ) =
2331 unpack( 'v4', substr( $sWk, $i * 8 + 2, 8 ) );
2332 for ( my $iR = $iRs ; $iR <= $iRe ; $iR++ ) {
2333 for ( my $iC = $iCs ; $iC <= $iCe ; $iC++ ) {
2334 $oWkS->{Cells}[$iR][$iC]->{Merged} = 1
2335 if ( defined $oWkS->{Cells}[$iR][$iC] );
2336 }
2337 }
2338 push @{ $oWkS->{MergedArea} }, [ $iRs, $iCs, $iRe, $iCe ];
2339 }
2340}
2341
2342#------------------------------------------------------------------------------
2343# DecodeBoolErr (for Spreadsheet::ParseExcel) DK: P306
2344#------------------------------------------------------------------------------
2345sub DecodeBoolErr {
2346 my ( $iVal, $iFlg ) = @_;
2347 if ( $iFlg ) { # ERROR
2348 if ( $iVal == 0x00 ) {
2349 return "#NULL!";
2350 }
2351 elsif ( $iVal == 0x07 ) {
2352 return "#DIV/0!";
2353 }
2354 elsif ( $iVal == 0x0F ) {
2355 return "#VALUE!";
2356 }
2357 elsif ( $iVal == 0x17 ) {
2358 return "#REF!";
2359 }
2360 elsif ( $iVal == 0x1D ) {
2361 return "#NAME?";
2362 }
2363 elsif ( $iVal == 0x24 ) {
2364 return "#NUM!";
2365 }
2366 elsif ( $iVal == 0x2A ) {
2367 return "#N/A!";
2368 }
2369 else {
2370 return "#ERR";
2371 }
2372 }
2373 else {
2374 return ( $iVal ) ? "TRUE" : "FALSE";
2375 }
2376}
2377
2378###############################################################################
2379#
2380# _decode_rk_number()
2381#
2382# Convert an encoded RK number into a real number. The RK encoding is
2383# explained in some detail in the MS docs. It is a way of storing applicable
2384# ints and doubles in 32bits (30 data + 2 info bits) in order to save space.
2385#
2386sub _decode_rk_number {
2387
2388 my $rk_number = shift;
2389 my $number;
2390
2391 # Check the main RK type.
2392 if ( $rk_number & 0x02 ) {
2393
2394 # RK Type 2 and 4, a packed integer.
2395
2396 # Shift off the info bits.
2397 $number = $rk_number >> 2;
2398
2399 # Convert from unsigned to signed if required.
2400 $number -= 0x40000000 if $number & 0x20000000;
2401 }
2402 else {
2403
2404 # RK Type 1 and 3, a truncated IEEE Double.
2405
2406 # Pack the RK number into the high 30 bits of an IEEE double.
2407 $number = pack "VV", 0x0000, $rk_number & 0xFFFFFFFC;
2408
2409 # Reverse the packed IEEE double on big-endian machines.
2410 $number = reverse $number if $BIGENDIAN;
2411
2412 # Unpack the number.
2413 $number = unpack "d", $number;
2414 }
2415
2416 # RK Types 3 and 4 were multiplied by 100 prior to encoding.
2417 $number /= 100 if $rk_number & 0x01;
2418
2419 return $number;
2420}
2421
2422###############################################################################
2423#
2424# _subStrWk()
2425#
2426# Extract the workbook strings from the SST (Shared String Table) record and
2427# any following CONTINUE records.
2428#
2429# The workbook strings are initially contained in the SST block but may also
2430# occupy one or more CONTINUE blocks. Reading the CONTINUE blocks is made a
2431# little tricky by the fact that they can contain an additional initial byte
2432# if a string is continued from a previous block.
2433#
2434# Parsing is further complicated by the fact that the continued section of the
2435# string may have a different encoding (ASCII or UTF-8) from the previous
2436# section. Excel does this to save space.
2437#
2438sub _subStrWk {
2439
2440 my ( $self, $biff_data, $is_continue ) = @_;
2441
2442 if ( $is_continue ) {
2443
2444 # We are reading a CONTINUE record.
2445
2446 if ( $self->{_buffer} eq '' ) {
2447
2448 # A CONTINUE block with no previous SST.
2449 $self->{_buffer} .= $biff_data;
2450 }
2451 elsif ( !defined $self->{_string_continued} ) {
2452
2453 # The CONTINUE block starts with a new (non-continued) string.
2454
2455 # Strip the Grbit byte and store the string data.
2456 $self->{_buffer} .= substr $biff_data, 1;
2457 }
2458 else {
2459
2460 # A CONTINUE block that starts with a continued string.
2461
2462 # The first byte (Grbit) of the CONTINUE record indicates if (0)
2463 # the continued string section is single bytes or (1) double bytes.
2464 my $grbit = ord $biff_data;
2465
2466 my ( $str_position, $str_length ) = @{ $self->{_previous_info} };
2467 my $buff_length = length $self->{_buffer};
2468
2469 if ( $buff_length >= ( $str_position + $str_length ) ) {
2470
2471 # Not in a string.
2472 $self->{_buffer} .= $biff_data;
2473 }
2474 elsif ( ( $self->{_string_continued} & 0x01 ) == ( $grbit & 0x01 ) )
2475 {
2476
2477 # Same encoding as the previous block of the string.
2478 $self->{_buffer} .= substr( $biff_data, 1 );
2479 }
2480 else {
2481
2482 # Different encoding to the previous block of the string.
2483 if ( $grbit & 0x01 ) {
2484
2485 # Current block is UTF-16, previous was ASCII.
2486 my ( undef, $cch ) = unpack 'vc', $self->{_buffer};
2487 substr( $self->{_buffer}, 2, 1 ) = pack( 'C', $cch | 0x01 );
2488
2489 # Convert the previous ASCII, single character, portion of
2490 # the string into a double character UTF-16 string by
2491 # inserting zero bytes.
2492 for (
2493 my $i = ( $buff_length - $str_position ) ;
2494 $i >= 1 ;
2495 $i--
2496 )
2497 {
2498 substr( $self->{_buffer}, $str_position + $i, 0 ) =
2499 "\x00";
2500 }
2501
2502 }
2503 else {
2504
2505 # Current block is ASCII, previous was UTF-16.
2506
2507 # Convert the current ASCII, single character, portion of
2508 # the string into a double character UTF-16 string by
2509 # inserting null bytes.
2510 my $change_length =
2511 ( $str_position + $str_length ) - $buff_length;
2512
2513 # Length of the current CONTINUE record data.
2514 my $biff_length = length $biff_data;
2515
2516 # Restrict the portion to be changed to the current block
2517 # if the string extends over more than one block.
2518 if ( $change_length > ( $biff_length - 1 ) * 2 ) {
2519 $change_length = ( $biff_length - 1 ) * 2;
2520 }
2521
2522 # Insert the null bytes.
2523 for ( my $i = ( $change_length / 2 ) ; $i >= 1 ; $i-- ) {
2524 substr( $biff_data, $i + 1, 0 ) = "\x00";
2525 }
2526
2527 }
2528
2529 # Strip the Grbit byte and store the string data.
2530 $self->{_buffer} .= substr $biff_data, 1;
2531 }
2532 }
2533 }
2534 else {
2535
2536 # Not a CONTINUE block therefore an SST block.
2537 $self->{_buffer} .= $biff_data;
2538 }
2539
2540 # Reset the state variables.
2541 $self->{_string_continued} = undef;
2542 $self->{_previous_info} = undef;
2543
2544 # Extract out any full strings from the current buffer leaving behind a
2545 # partial string that is continued into the next block, or an empty
2546 # buffer is no string is continued.
2547 while ( length $self->{_buffer} >= 4 ) {
2548 my ( $str_info, $length, $str_position, $str_length ) =
2549 _convBIFF8String( $self, $self->{_buffer}, 1 );
2550
2551 if ( defined $str_info->[0] ) {
2552 push @{ $self->{PkgStr} },
2553 {
2554 Text => $str_info->[0],
2555 Unicode => $str_info->[1],
2556 Rich => $str_info->[2],
2557 Ext => $str_info->[3],
2558 };
2559 $self->{_buffer} = substr( $self->{_buffer}, $length );
2560 }
2561 else {
2562 $self->{_string_continued} = $str_info->[1];
2563 $self->{_previous_info} = [ $str_position, $str_length ];
2564 last;
2565 }
2566 }
2567}
2568
2569#------------------------------------------------------------------------------
2570# _SwapForUnicode (for Spreadsheet::ParseExcel)
2571#------------------------------------------------------------------------------
2572sub _SwapForUnicode {
2573 my ( $sObj ) = @_;
2574
2575 # for(my $i = 0; $i<length($$sObj); $i+=2){
2576 for ( my $i = 0 ; $i < ( int( length( $$sObj ) / 2 ) * 2 ) ; $i += 2 ) {
2577 my $sIt = substr( $$sObj, $i, 1 );
2578 substr( $$sObj, $i, 1 ) = substr( $$sObj, $i + 1, 1 );
2579 substr( $$sObj, $i + 1, 1 ) = $sIt;
2580 }
2581}
2582
2583#------------------------------------------------------------------------------
2584# _NewCell (for Spreadsheet::ParseExcel)
2585#------------------------------------------------------------------------------
2586sub _NewCell {
2587 my ( $oBook, $iR, $iC, %rhKey ) = @_;
2588 my ( $sWk, $iLen );
2589 return undef unless ( defined $oBook->{_CurSheet} );
2590
2591 my $FmtClass = $oBook->{FmtClass};
2592 $rhKey{Type} =
2593 $FmtClass->ChkType( $rhKey{Numeric}, $rhKey{Format}{FmtIdx} );
2594 my $FmtStr = $oBook->{FormatStr}{ $rhKey{Format}{FmtIdx} };
2595
2596 # Set "Date" type if required for numbers in a MulRK BIFF block.
2597 if ( defined $FmtStr && $rhKey{Type} eq "Numeric" ) {
2598
2599 # Match a range of possible date formats. Note: this isn't important
2600 # except for reporting. The number will still be converted to a date
2601 # by ExcelFmt() even if 'Type' isn't set to 'Date'.
2602 if ( $FmtStr =~ m{^[dmy][-\\/dmy]*$}i ) {
2603 $rhKey{Type} = "Date";
2604 }
2605 }
2606
2607 my $oCell = Spreadsheet::ParseExcel::Cell->new(
2608 Val => $rhKey{Val},
2609 FormatNo => $rhKey{FormatNo},
2610 Format => $rhKey{Format},
2611 Code => $rhKey{Code},
2612 Type => $rhKey{Type},
2613 );
2614 $oCell->{_Kind} = $rhKey{Kind};
2615 $oCell->{_Value} = $FmtClass->ValFmt( $oCell, $oBook );
2616 if ( $rhKey{Rich} ) {
2617 my @aRich = ();
2618 my $sRich = $rhKey{Rich};
2619 for ( my $iWk = 0 ; $iWk < length( $sRich ) ; $iWk += 4 ) {
2620 my ( $iPos, $iFnt ) = unpack( 'v2', substr( $sRich, $iWk ) );
2621 push @aRich, [ $iPos, $oBook->{Font}[$iFnt] ];
2622 }
2623 $oCell->{Rich} = \@aRich;
2624 }
2625
2626 if ( defined $oBook->{CellHandler} ) {
2627 if ( defined $oBook->{Object} ) {
26282190µs213µs
# spent 10µs (7+3) within Spreadsheet::ParseExcel::BEGIN@2628 which was called: # once (7µs+3µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 2628
no strict;
# spent 10µs making 1 call to Spreadsheet::ParseExcel::BEGIN@2628 # spent 3µs making 1 call to strict::unimport
2629 ref( $oBook->{CellHandler} ) eq "CODE"
2630 ? $oBook->{CellHandler}->(
2631 $_Object, $oBook, $oBook->{_CurSheet}, $iR, $iC, $oCell
2632 )
2633 : $oBook->{CellHandler}->callback( $_Object, $oBook, $oBook->{_CurSheet},
2634 $iR, $iC, $oCell );
2635 }
2636 else {
2637 $oBook->{CellHandler}->( $oBook, $oBook->{_CurSheet}, $iR, $iC, $oCell );
2638 }
2639 }
2640 unless ( $oBook->{NotSetCell} ) {
2641 $oBook->{Worksheet}[ $oBook->{_CurSheet} ]->{Cells}[$iR][$iC] = $oCell;
2642 }
2643 return $oCell;
2644}
2645
2646#------------------------------------------------------------------------------
2647# ColorIdxToRGB (for Spreadsheet::ParseExcel)
2648#
2649# Returns for most recently opened book for compatibility, use
2650# Workbook::color_idx_to_rgb instead
2651#
2652#------------------------------------------------------------------------------
2653sub ColorIdxToRGB {
2654 my ( $sPkg, $iIdx ) = @_;
2655
2656
2657 unless( defined $currentbook ) {
2658 return ( ( defined $aColor[$iIdx] ) ? $aColor[$iIdx] : $aColor[0] );
2659 }
2660
2661 return $currentbook->color_idx_to_rgb( $iIdx );
2662}
2663
2664
2665###############################################################################
2666#
2667# error().
2668#
2669# Return an error string for a failed parse().
2670#
2671sub error {
2672
2673 my $self = shift;
2674
2675 my $parse_error = $self->{_error_status};
2676
2677 if ( exists $error_strings{$parse_error} ) {
2678 return $error_strings{$parse_error};
2679 }
2680 else {
2681 return 'Unknown parse error';
2682 }
2683}
2684
2685
2686###############################################################################
2687#
2688# error_code().
2689#
2690# Return an error code for a failed parse().
2691#
2692sub error_code {
2693
2694 my $self = shift;
2695
2696 return $self->{_error_status};
2697}
2698
2699
2700###############################################################################
2701#
2702# Mapping between legacy method names and new names.
2703#
2704{
2705357µs231µs
# spent 18µs (5+13) within Spreadsheet::ParseExcel::BEGIN@2705 which was called: # once (5µs+13µs) by Spreadsheet::ParseXLSX::BEGIN@14 at line 2705
no warnings; # Ignore warnings about variables used only once.
# spent 18µs making 1 call to Spreadsheet::ParseExcel::BEGIN@2705 # spent 13µs making 1 call to warnings::unimport
270611µs *Parse = *parse;
2707}
2708
2709114µs1;
2710
2711__END__
 
# spent 4µs within Spreadsheet::ParseExcel::__ANON__ which was called 6 times, avg 667ns/call: # once (800ns+0s) by Spreadsheet::ParseExcel::BEGIN@36 at line 36 # once (700ns+0s) by Spreadsheet::ParseExcel::BEGIN@33 at line 33 # once (700ns+0s) by Spreadsheet::ParseExcel::BEGIN@34 at line 34 # once (600ns+0s) by Spreadsheet::ParseExcel::BEGIN@32 at line 32 # once (600ns+0s) by Spreadsheet::ParseExcel::BEGIN@31 at line 31 # once (600ns+0s) by Spreadsheet::ParseExcel::BEGIN@35 at line 35
sub Spreadsheet::ParseExcel::__ANON__; # xsub