Skip to content

Commit

Permalink
Refactor cells and rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed Aug 24, 2023
1 parent dc82062 commit dfa42ef
Show file tree
Hide file tree
Showing 5 changed files with 402 additions and 369 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ try {
$worksheetName = $xlsxFastEditor->getWorksheetName(1);
$worksheetId1 = $xlsxFastEditor->getWorksheetNumber('Sheet1');
$worksheetId2 = $xlsxFastEditor->getWorksheetNumber('Sheet2');
// If you want to force Excel to recalculate formulas on next load:
$xlsxFastEditor->setFullCalcOnLoad($worksheetId2, true);

// Direct read access
// Direct read/write access
$fx = $xlsxFastEditor->readFormula($worksheetId1, 'A1');
$f = $xlsxFastEditor->readFloat($worksheetId1, 'B2');
$i = $xlsxFastEditor->readInt($worksheetId1, 'C3');
$s = $xlsxFastEditor->readString($worksheetId2, 'D4');
$xlsxFastEditor->deleteRow($worksheetId1, 5);
$xlsxFastEditor->writeFormula($worksheetId1, 'A1', '=B2*3');
$xlsxFastEditor->writeFloat($worksheetId1, 'B2', 3.14);
$xlsxFastEditor->writeInt($worksheetId1, 'C3', 13);
$xlsxFastEditor->writeString($worksheetId2, 'D4', 'Hello');

// Regex search & replace operating globally on all the worksheets:
$xlsxFastEditor->textReplace('/Hello/i', 'World');

// Navigation methods for existing rows
$row = $xlsxFastEditor->getFirstRow($worksheetId1);
Expand All @@ -65,7 +75,7 @@ try {
$row = $row->getNextRow();
$row = $xlsxFastEditor->getLastRow($worksheetId1);

// Read methods for rows
// Methods for rows
$rowNumber = $row->number();

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

// Read methods for cells
// Methods for cells
$cellName = $cell->name();
$fx = $cell->readFormula();
$f = $cell->readFloat();
$i = $cell->readInt();
$s = $cell->readString();
$cell->writeFormula('=B2*3');
$cell->writeFloat(3.14);
$cell->writeInt(13);
$cell->writeString('Hello');

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

// If you want to force Excel to recalculate formulas on next load:
$xlsxFastEditor->setFullCalcOnLoad($worksheetId2, true);

// Direct write access
$xlsxFastEditor->deleteRow($worksheetId1, 5);
$xlsxFastEditor->writeFormula($worksheetId1, 'A1', '=B2*3');
$xlsxFastEditor->writeFloat($worksheetId1, 'B2', 3.14);
$xlsxFastEditor->writeInt($worksheetId1, 'C3', 13);
$xlsxFastEditor->writeString($worksheetId2, 'D4', 'Hello');

// Regex search & replace operating globally on all the worksheets:
$xlsxFastEditor->textReplace('/Hello/i', 'World');

$xlsxFastEditor->save();
// If you do not want to save, call `close()` instead:
// $xlsxFastEditor->close();
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent.NonIndentTabsUsed"/>
<exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
</rule>
<rule ref="PSR12"/>
<rule ref="Generic.Classes.DuplicateClassName"/>
Expand Down
Loading

0 comments on commit dfa42ef

Please sign in to comment.