使用 col 和行索引的 PHP Excel 样式格式



我们可以像这样在单元格范围内应用样式

$objPHPExcel->getActiveSheet()->duplicateStyleArray($array_of_style,"A1:D1");

但是我想把相同的样式应用到单元格的列和行引用上,比如

(3,4,7,7); 

请帮我一下。我不是phpexcel的新手,但找不到任何方法来应用样式在col &行索引。

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);
}

最新更新