dpt62283 2014-02-12 01:53
浏览 157
已采纳

PHPEXCEL:如何基于数组值合并excel行

this my MySQL to generate the array :

$sql_name = "SELECT * FROM ".TABLE_PREFIX."members WHERE member_id IN ($member_id) order by member_id DESC";

$result_name = mysql_query($sql_name, $db);

$name = array();
while ($row = mysql_fetch_assoc($result_name)) {
    $arr1= $row['first_name'];
    $arr = array_push($name ,$arr1);
}

$name1[] = $name;
$objPHPExcel->setActiveSheetIndex()->fromArray($name1, NULL, 'C20');

This is the result that i get :

enter image description here

Output that i want is each array will fill 2 rows means it will take next column and merge it like this below image. How can possible to use merge?.. i new to this. please help me. thanks!

enter image description here

SOLUTION FOR MY QUESTION FOR REFERENCE LATER :

for($row = 20; $row <= 2; $row++) { 

$objPHPExcel->setActiveSheetIndex()->fromArray($name1, NULL, 'C20')->mergeCells('C' . $row . ':D' . $row);
}

and i change my sql .. by adding empty space to the array :

  $arr = array_push($name ,$arr1,'');
  • 写回答

1条回答 默认 最新

  • dpitqpax07626 2014-02-12 08:11
    关注

    To merge cells in PHPExcel, you can use

    $objPHPExcel->getActiveSheet()
        ->mergeCells('C29:D29');
    

    as described in section 4.6.34 of the developer documentation, entitled "Merge/unmerge cells", but it's up to you to ensure that the correct data is written and formatted in those cells

    EDIT

    The range argument is simply a string, so you can use standard PHP concatenation to build it dynamically in a loop.

    for($row = 1; $row <= 100; $row++) {
        $objPHPExcel->getActiveSheet()
            ->mergeCells('C' . $row . ':D' . $row);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划