使用col&row索引的PHP Excel样式格式

Pra*_*vin 3 php phpexcel

我们可以在这样的单元格上应用样式

$objPHPExcel->getActiveSheet()->duplicateStyleArray($array_of_style,"A1:D1");
Run Code Online (Sandbox Code Playgroud)

但我想将相同的样式应用于其列和行引用上的一系列单元格

(3,4,7,7); 
Run Code Online (Sandbox Code Playgroud)

请帮帮我.我不是phpexcel上的新手,但找不到任何方法在col&row index中给出的范围上应用样式.

Mar*_*ker 6

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);
}
Run Code Online (Sandbox Code Playgroud)