PHP Excel style formatting using col & row index

若如初见. 提交于 2019-12-10 18:11:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!