问题
we can apply a style on a range of cells like this
$objPHPExcel->getActiveSheet()->duplicateStyleArray($array_of_style,"A1:D1");
But I want to apply same style to a range of cells on their column and row reference like
(3,4,7,7);
Please help me on this. I am not a newbie on phpexcel but could not find any method to apply a style on range given in col & row index.
回答1:
function duplicateStyleArrayByColumnAndRow( PHPExcel $objPHPExcel,
$styleArray = array(),
$fromRow = 1,
$fromCol = 0,
$toRow = 1,
$toCol = 0
)
{
if ($fromRow > $toRow) {
$r = $fromRow; $fromRow = $toRow; $toRow = $r;
}
if ($fromCol > $toCol) {
$c = $fromCol; $fromCol = $toCol; $toCol = $c;
}
$fromCell = PHPExcel_Cell::stringFromColumnIndex($fromCol) . $fromRow;
$toCell = PHPExcel_Cell::stringFromColumnIndex($toCol) . $toRow;
$cellRange = $fromCell . ':' . $toCell;
if ($fromCell === $toCell) {
$cellRange = $fromCell;
}
return $objPHPExcel->getActiveSheet()->duplicateStyleArray($styleArray,$cellRange);
}
来源:https://stackoverflow.com/questions/7836688/php-excel-style-formatting-using-col-row-index