Maggi
Maggi

Reputation: 173

How to get correct Cell Coordinate values

I am trying to style my excel sheet rows upto certain column. number of Column are dynamically changes as per application. I can count the number of column by counting the array size like

$ColSize = sizeOf(excel_out)  

now i want to style it like this

for ($i= 0 ; $i<= $highestRow;$i++)
    {
        if ($objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue() == 'Responses')
        {
            $objPHPExcel->getActiveSheet()->getStyle('A'.$i.':'.$ColSize.$i)->applyFromArray($Heading2Style);


        }
    }

but it gives the error that "Invalid cell coordinate" I guess it's not getting the alphabet count for columns it just getting numeric value per cell like eg : 21=> B1 31=>C1 . how can i get the correct coordinate value ??

Upvotes: 0

Views: 791

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

Convert $ColSize to an alpha column address value using the static stringFromColumnIndex() helper method of the PHPExcel_Cell class

$objPHPExcel->getActiveSheet()
    ->getStyle('A' . $i . ':' . PHPExcel_Cell::stringFromColumnIndex($ColSize) . $i)
    ->applyFromArray($Heading2Style);

Upvotes: 1

mgaido
mgaido

Reputation: 3055

What is there into $ColSize? Maybe you need to use:

 $columnString=PHPExcel_Cell::stringFromColumnIndex($ColSize);
 $objPHPExcel->getActiveSheet()->getStyle('A'.$i.':'.$columnString.$i)->applyFromArray($Heading2Style);

Upvotes: 2

Related Questions