Skip to content

Commit dfa42ef

Browse files
committed
Refactor cells and rows
1 parent dc82062 commit dfa42ef

File tree

5 files changed

+402
-369
lines changed

5 files changed

+402
-369
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@ try {
5151
$worksheetName = $xlsxFastEditor->getWorksheetName(1);
5252
$worksheetId1 = $xlsxFastEditor->getWorksheetNumber('Sheet1');
5353
$worksheetId2 = $xlsxFastEditor->getWorksheetNumber('Sheet2');
54+
// If you want to force Excel to recalculate formulas on next load:
55+
$xlsxFastEditor->setFullCalcOnLoad($worksheetId2, true);
5456

55-
// Direct read access
57+
// Direct read/write access
5658
$fx = $xlsxFastEditor->readFormula($worksheetId1, 'A1');
5759
$f = $xlsxFastEditor->readFloat($worksheetId1, 'B2');
5860
$i = $xlsxFastEditor->readInt($worksheetId1, 'C3');
5961
$s = $xlsxFastEditor->readString($worksheetId2, 'D4');
62+
$xlsxFastEditor->deleteRow($worksheetId1, 5);
63+
$xlsxFastEditor->writeFormula($worksheetId1, 'A1', '=B2*3');
64+
$xlsxFastEditor->writeFloat($worksheetId1, 'B2', 3.14);
65+
$xlsxFastEditor->writeInt($worksheetId1, 'C3', 13);
66+
$xlsxFastEditor->writeString($worksheetId2, 'D4', 'Hello');
67+
68+
// Regex search & replace operating globally on all the worksheets:
69+
$xlsxFastEditor->textReplace('/Hello/i', 'World');
6070

6171
// Navigation methods for existing rows
6272
$row = $xlsxFastEditor->getFirstRow($worksheetId1);
@@ -65,7 +75,7 @@ try {
6575
$row = $row->getNextRow();
6676
$row = $xlsxFastEditor->getLastRow($worksheetId1);
6777

68-
// Read methods for rows
78+
// Methods for rows
6979
$rowNumber = $row->number();
7080

7181
// Navigation methods for existing cells
@@ -75,12 +85,16 @@ try {
7585
$cell = $cell->getNextCell();
7686
$cell = $row->getLastCell();
7787

78-
// Read methods for cells
88+
// Methods for cells
7989
$cellName = $cell->name();
8090
$fx = $cell->readFormula();
8191
$f = $cell->readFloat();
8292
$i = $cell->readInt();
8393
$s = $cell->readString();
94+
$cell->writeFormula('=B2*3');
95+
$cell->writeFloat(3.14);
96+
$cell->writeInt(13);
97+
$cell->writeString('Hello');
8498

8599
// Iterators for existing rows and cells
86100
foreach ($xlsxFastEditor->rowsIterator($worksheetId1) as $row) {
@@ -89,19 +103,6 @@ try {
89103
}
90104
}
91105

92-
// If you want to force Excel to recalculate formulas on next load:
93-
$xlsxFastEditor->setFullCalcOnLoad($worksheetId2, true);
94-
95-
// Direct write access
96-
$xlsxFastEditor->deleteRow($worksheetId1, 5);
97-
$xlsxFastEditor->writeFormula($worksheetId1, 'A1', '=B2*3');
98-
$xlsxFastEditor->writeFloat($worksheetId1, 'B2', 3.14);
99-
$xlsxFastEditor->writeInt($worksheetId1, 'C3', 13);
100-
$xlsxFastEditor->writeString($worksheetId2, 'D4', 'Hello');
101-
102-
// Regex search & replace operating globally on all the worksheets:
103-
$xlsxFastEditor->textReplace('/Hello/i', 'World');
104-
105106
$xlsxFastEditor->save();
106107
// If you do not want to save, call `close()` instead:
107108
// $xlsxFastEditor->close();

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<rule ref="PSR2">
77
<exclude name="Generic.WhiteSpace.DisallowTabIndent.NonIndentTabsUsed"/>
88
<exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"/>
9+
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
910
</rule>
1011
<rule ref="PSR12"/>
1112
<rule ref="Generic.Classes.DuplicateClassName"/>

0 commit comments

Comments
 (0)