1

I am using PHPExcel to put some comments to cells. But if I put range, than I see error:

Cell coordinate string can not be a range of cells.

I need a function that can convert my range to array of cells for loop.

For example, if I have (A6:A11) => array(A6, A7, A8, A9, A10, A11).

How to do it?

Sogl
  • 782
  • 3
  • 9
  • 29

1 Answers1

1

You can't specify a range of cells when using the need to set each comment individually

But there is a helper function that will allow you to split a range string to an array of individual cell addresses that you can then loop over:

foreach(PHPExcel_Cell::extractAllCellReferencesInRange('A6:A11') as $cellAddress) {
    $objCommentRichText = $objPHPExcel->getActiveSheet()
        ->getComment($cellAddress)
        ->getText()
        ->createTextRun('My comment for all cells in the range A6 to A11');
}
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Thanks, Mark! This function also works with individual cell, not only for range of cells. No need to add conditions to check range before. – Sogl Jul 30 '15 at 23:11