Skip to content

Deprecate ByColumnAndRow() methods in Worksheet #2717

Description

@MarkBaker

Discussed in #2706

Originally posted by MarkBaker March 20, 2022
I'm planning version 2.0 with some bc breaks, and I'm looking at dropping methods like setCellValueByColumnAndRow() which accepts column and row number arguments, leaving only setCellValue() which requires a cell address as a string value(e.g. 'C5').
There are 14 such methods defined in the WorkSheet class:

  • setCellValueByColumnAndRow() has equivalent setCellValue()
  • setCellValueExplicitByColumnAndRow() has equivalent setCellValueExplicit()
  • getCellByColumnAndRow() has equivalent getCell()
  • cellExistsByColumnAndRow() has equivalent cellExists()
  • getStyleByColumnAndRow() has equivalent getStyle()
  • setBreakByColumnAndRow() has equivalent setBreak()
  • mergeCellsByColumnAndRow() has equivalent mergeCells()
  • unmergeCellsByColumnAndRow() has equivalent unmergeCells()
  • protectCellsByColumnAndRow() has equivalent protectCells()
  • unprotectCellsByColumnAndRow() has equivalent unprotectCells()
  • setAutoFilterByColumnAndRow() has equivalent setAutoFilter()
  • freezePaneByColumnAndRow() has equivalent freezePane()
  • getCommentByColumnAndRow() has equivalent getComment()
  • setSelectedCellByColumnAndRow() has equivalent setSelectedCells()

There is some inconsistency here, with other methods that only accept a cell address like IV255 and that have no "byColumnAndRow" eqivalent (e.g setTopLeftCell() and setSelectedCell()); so this deprecation will provide more consistency.

The base methods already provide more flexibility than the byColumnAndRow() methods

There are also a couple of column-only methods:

  • getColumnDimensionByColumn() has equivalent getColumnDimension()
  • insertNewColumnBeforeByIndex() has equivalent insertNewColumnBefore()

A CellAddress object could be defined with static creator methods like fromRowAndColumn($rowIndex, $columnIndex), fromColumnAndRow($columnIndex, $rowIndex), fromCoordinate($cellAddress), etc; and provide getters to retrieve rowIndex, columnIndex, columnString, cellAddress, etc, giving it a lot more flexibility.

These base methods will be re-defined to accept either a string, an array of columnId/RowId or a CellAddress object.

setCellValue(string|array|CellAddress $coordinate, $value){}

Those that accept a range of cells will be re-defined to accept either a string, an array of columnId/RowId, a CellAddress object, or a CellRange object.

mergeCells(string|array|CellAddress|CellRange $range){}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions