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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?