|
11 | 11 | class DimensionsRecordTest extends TestCase |
12 | 12 | { |
13 | 13 | /** |
14 | | - * Test that DIMENSIONS record uses 0-based column indices. |
| 14 | + * Test that DIMENSIONS record uses 0-based indices for both rows and columns. |
15 | 15 | * |
16 | 16 | * This test verifies that the BIFF8 DIMENSIONS record correctly uses 0-based |
17 | | - * column indices. Prior to the fix, columnIndexFromString() returned 1-based |
18 | | - * indices which were written directly to the DIMENSIONS record, causing issues |
19 | | - * with old XLS parsers that expect 0-based indices per the BIFF8 specification. |
| 17 | + * indices for both rows and columns. Prior to the fix, 1-based values were |
| 18 | + * written directly to the DIMENSIONS record, causing issues with old XLS parsers |
| 19 | + * that expect 0-based indices per the BIFF8 specification. |
20 | 20 | * |
21 | 21 | * The DIMENSIONS record structure (BIFF8): |
22 | | - * - Offset 0-3: Index to first used row |
23 | | - * - Offset 4-7: Index to last used row + 1 |
| 22 | + * - Offset 0-3: Index to first used row (0-based) |
| 23 | + * - Offset 4-7: Index to last used row + 1 (0-based) |
24 | 24 | * - Offset 8-9: Index to first used column (0-based) |
25 | 25 | * - Offset 10-11: Index to last used column + 1 (0-based) |
26 | 26 | * - Offset 12-13: Not used |
| 27 | + * |
| 28 | + * Note: All indices in the DIMENSIONS record are 0-based, meaning Excel row 1 |
| 29 | + * is stored as 0, row 5 as 4, column A as 0, column D as 3, etc. |
27 | 30 | */ |
28 | 31 | public function testDimensionsRecordUsesZeroBasedColumnIndices(): void |
29 | 32 | { |
@@ -62,22 +65,22 @@ public function testDimensionsRecordUsesZeroBasedColumnIndices(): void |
62 | 65 | $data = unpack('VrwMic/VrwMac/vcolMic/vcolMac/vreserved', $dimensionsData); |
63 | 66 | self::assertIsArray($data, 'Failed to unpack DIMENSIONS record'); |
64 | 67 |
|
65 | | - // Verify the values are correct (0-based for columns, 1-based for rows) |
66 | | - // First used row is 1 |
67 | | - self::assertSame(1, $data['rwMic'], 'First row should be 1'); |
| 68 | + // Verify the values are correct (0-based for both rows and columns) |
| 69 | + // First used row is 1 (Excel UI), which is 0 in 0-based indexing |
| 70 | + self::assertSame(0, $data['rwMic'], 'First row should be 0 (0-based)'); |
68 | 71 |
|
69 | | - // Last used row is 5, so rwMac should be 6 (last row + 1) |
70 | | - self::assertSame(6, $data['rwMac'], 'Last row + 1 should be 6'); |
| 72 | + // Last used row is 5 (Excel UI), which is 4 in 0-based, so rwMac should be 5 (4 + 1) |
| 73 | + self::assertSame(5, $data['rwMac'], 'Last row + 1 should be 5 (0-based row 4 + 1)'); |
71 | 74 |
|
72 | | - // First column is A (0-based: 0) |
| 75 | + // First column is A (Excel UI), which is 0 in 0-based indexing |
73 | 76 | // BEFORE FIX: This would be 1 (because columnIndexFromString('A') returns 1) |
74 | | - // AFTER FIX: This should be 0 (because we subtract 1) |
| 77 | + // AFTER FIX: This is 0 (because we subtract 1) |
75 | 78 | self::assertSame(0, $data['colMic'], 'First column should be 0 (0-based for column A)'); |
76 | 79 |
|
77 | | - // Last column is D (0-based index 3), so colMac should be 4 (last used + 1) |
| 80 | + // Last column is D (Excel UI), which is 3 in 0-based, so colMac should be 4 (3 + 1) |
78 | 81 | // BEFORE FIX: This would be 5 (columnIndexFromString('D') = 4, not adjusted to 0-based) |
79 | | - // AFTER FIX: This should be 4 (columnIndexFromString('D') - 1 = 3, + 1 = 4) |
80 | | - self::assertSame(4, $data['colMac'], 'Last column + 1 should be 4 (0-based for column D + 1)'); |
| 82 | + // AFTER FIX: This is 4 (columnIndexFromString('D') - 1 = 3, + 1 = 4) |
| 83 | + self::assertSame(4, $data['colMac'], 'Last column + 1 should be 4 (0-based column 3 + 1)'); |
81 | 84 | } |
82 | 85 |
|
83 | 86 | /** |
|
0 commit comments