1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Reader\Xls; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xls; |
8
|
|
|
|
9
|
|
|
class Biff5 extends Xls |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Reads a cell range address in BIFF5 e.g. 'A2:B6' or 'A1' |
13
|
|
|
* always fixed range |
14
|
|
|
* section 2.5.14. |
15
|
|
|
*/ |
16
|
116 |
|
public static function readBIFF5CellRangeAddressFixed(string $subData): string |
17
|
|
|
{ |
18
|
|
|
// offset: 0; size: 2; index to first row |
19
|
116 |
|
$fr = self::getUInt2d($subData, 0) + 1; |
20
|
|
|
|
21
|
|
|
// offset: 2; size: 2; index to last row |
22
|
116 |
|
$lr = self::getUInt2d($subData, 2) + 1; |
23
|
|
|
|
24
|
|
|
// offset: 4; size: 1; index to first column |
25
|
116 |
|
$fc = ord($subData[4]); |
26
|
|
|
|
27
|
|
|
// offset: 5; size: 1; index to last column |
28
|
116 |
|
$lc = ord($subData[5]); |
29
|
|
|
|
30
|
|
|
// check values |
31
|
116 |
|
if ($fr > $lr || $fc > $lc) { |
32
|
|
|
throw new ReaderException('Not a cell range address'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// column index to letter |
36
|
116 |
|
$fc = Coordinate::stringFromColumnIndex($fc + 1); |
37
|
116 |
|
$lc = Coordinate::stringFromColumnIndex($lc + 1); |
38
|
|
|
|
39
|
116 |
|
if ($fr == $lr && $fc == $lc) { |
40
|
96 |
|
return "$fc$fr"; |
41
|
|
|
} |
42
|
|
|
|
43
|
34 |
|
return "$fc$fr:$lc$lr"; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Read BIFF5 cell range address list |
48
|
|
|
* section 2.5.15. |
49
|
|
|
* |
50
|
|
|
* @return array{size: int, cellRangeAddresses: string[]} |
51
|
|
|
*/ |
52
|
116 |
|
public static function readBIFF5CellRangeAddressList(string $subData): array |
53
|
|
|
{ |
54
|
116 |
|
$cellRangeAddresses = []; |
55
|
|
|
|
56
|
|
|
// offset: 0; size: 2; number of the following cell range addresses |
57
|
116 |
|
$nm = self::getUInt2d($subData, 0); |
58
|
|
|
|
59
|
116 |
|
$offset = 2; |
60
|
|
|
// offset: 2; size: 6 * $nm; list of $nm (fixed) cell range addresses |
61
|
116 |
|
for ($i = 0; $i < $nm; ++$i) { |
62
|
116 |
|
$cellRangeAddresses[] = self::readBIFF5CellRangeAddressFixed(substr($subData, $offset, 6)); |
63
|
116 |
|
$offset += 6; |
64
|
|
|
} |
65
|
|
|
|
66
|
116 |
|
return [ |
67
|
116 |
|
'size' => 2 + 6 * $nm, |
68
|
116 |
|
'cellRangeAddresses' => $cellRangeAddresses, |
69
|
116 |
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|