使用 col 和 row 索引的 PHPExcel 样式格式化

标签 php phpexcel

我们可以像这样在一系列单元格上应用样式

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

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

(3,4,7,7); 

请帮我解决这个问题。我不是 phpexcel 的新手,但找不到任何方法在列和行索引中给定的范围内应用样式。

最佳答案

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

关于使用 col 和 row 索引的 PHPExcel 样式格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7836688/

相关文章:

javascript - 使用 LinkedIn 登录 PHP 代码问题

mysql - PHPExcel MySQL 导出 w2 查询

php - 如何在PHPExcel报表中连接数组中的数据

php - 在 Flex 中嵌入浏览器

php - 将mysql数据库导出到excel

PHPExcel 1.8.0 - 通过克隆模板表创建许多工作表,每次克隆都会变慢

PHPExcel - 未正确获取引用另一个单元格的单元格的值

php - WordPress 网站 Hook 错误

javascript - 如果脚本已更新,如何刷新页面的缓存?

php - 创建 whois 查询的最佳方法是什么?