| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xls; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
| 6 |
use TablePress\PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; |
| 7 |
use TablePress\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 |
public static function readBIFF5CellRangeAddressFixed(string $subData): string |
| 17 |
{ |
| 18 |
// offset: 0; size: 2; index to first row |
| 19 |
$fr = self::getUInt2d($subData, 0) + 1; |
| 20 |
|
| 21 |
// offset: 2; size: 2; index to last row |
| 22 |
$lr = self::getUInt2d($subData, 2) + 1; |
| 23 |
|
| 24 |
// offset: 4; size: 1; index to first column |
| 25 |
$fc = ord($subData[4]); |
| 26 |
|
| 27 |
// offset: 5; size: 1; index to last column |
| 28 |
$lc = ord($subData[5]); |
| 29 |
|
| 30 |
// check values |
| 31 |
if ($fr > $lr || $fc > $lc) { |
| 32 |
throw new ReaderException('Not a cell range address'); |
| 33 |
} |
| 34 |
|
| 35 |
// column index to letter |
| 36 |
$fc = Coordinate::stringFromColumnIndex($fc + 1); |
| 37 |
$lc = Coordinate::stringFromColumnIndex($lc + 1); |
| 38 |
|
| 39 |
if ($fr == $lr && $fc == $lc) { |
| 40 |
return "$fc$fr"; |
| 41 |
} |
| 42 |
|
| 43 |
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 |
public static function readBIFF5CellRangeAddressList(string $subData): array |
| 53 |
{ |
| 54 |
$cellRangeAddresses = []; |
| 55 |
|
| 56 |
// offset: 0; size: 2; number of the following cell range addresses |
| 57 |
$nm = self::getUInt2d($subData, 0); |
| 58 |
|
| 59 |
$offset = 2; |
| 60 |
// offset: 2; size: 6 * $nm; list of $nm (fixed) cell range addresses |
| 61 |
for ($i = 0; $i < $nm; ++$i) { |
| 62 |
$cellRangeAddresses[] = self::readBIFF5CellRangeAddressFixed((string) substr($subData, $offset, 6)); |
| 63 |
$offset += 6; |
| 64 |
} |
| 65 |
|
| 66 |
return [ |
| 67 |
'size' => 2 + 6 * $nm, |
| 68 |
'cellRangeAddresses' => $cellRangeAddresses, |
| 69 |
]; |
| 70 |
} |
| 71 |
} |
| 72 |
|