Set shared style by using numeric cell coordinates

Topics: Developer Forum
Mar 23, 2009 at 9:28 AM
What do you think about adding method which allow set shared style by using numeric cell coordinates? Something like setSharedStyleByColumnAndRow() ? Also with possibility to use range?

Right now im using something like:
$sheet->setSharedStyle($style1, PHPExcel_Cell::stringFromColumnIndex($columnIndex).$rowIndex);

Which is quite ugly i think.
Developer
Mar 24, 2009 at 8:21 PM
Yes, I agree, it is a bit ugly. But I think we should wait introducing setSharedStyleByColumnAndRow() until it is clear what the preferred method for styling will be in the future. The setSharedStyle() method is good in some cases, but not perfect. Therefore the use of it has not been promoted in the documentation. In the future it may not be needed, duplicateStyle() should be able to work with shared styles automatically.
Mar 31, 2009 at 9:29 AM
Personally even if duplicateStyle() instead cloning style objects will use shared styles I will still prefer setSharedStyle() way. I can first create a style object and then assign it to any cell. With duplicateStyle() I don't have this possibility. Or maybe is there other way to attach predefined style to cell? There is applyFromArray() but I prefer to use object.
Developer
Mar 31, 2009 at 1:37 PM
Actually, you have that possibility with duplicateStyle. Notice the similarity:

$objWorksheet->setSharedStyle($objStyle, 'A1')
$objWorksheet->setSharedStyle($objStyle, 'A1:D4')

$objWorksheet->duplicateStyle($objStyle, 'A1')
$objWorksheet->duplicateStyle($objStyle, 'A1:D4')

As classes are built now, they are not doing the same since under the hood duplicateStyle is cloning the style, one for each cell in the range. In the future, it should be possible to avoid this and the two methods will be quite the same.

Dec 26, 2012 at 4:48 AM

Buscando una solucion encontre tu post, despues vi el codigo fuente de las librerias y edite la funcion "setSharedStyle" para adecuarla a nuestras necesidades..

http://phpexcel.codeplex.com/discussions/418596