7

Suppose I want to set collapse and expand for row 2 up to 4 as one group, and 8 up to 12 the second group. It means when user want to click on expand + icon of group 1, rows from 2 up to 4 should be visible, and for group 2 row from 8 up to 12 should be visible. Bellow is the code for single row.

$sheet->getRowDimension(1)->setOutlineLevel(1);

$sheet->getRowDimension(1)->setVisible(false);

$sheet->getRowDimension(1)->setCollapsed(true);

And the other question is, can we define the expand icon ourself instead of + icon? some thing like this

jones
  • 1,423
  • 3
  • 35
  • 76

1 Answers1

12

You can set an outline group over a range of rows (or columns) by setting it for each row; and you can nest outline groups by setting the group level argument.

// Set outline levels
for ($row = 2; $row <= 10; ++$row) {
    $objPHPExcel->getActiveSheet()
        ->getRowDimension($row)
            ->setOutlineLevel(1)
            ->setVisible(false)
            ->setCollapsed(true);
}

for ($row = 4; $row <= 9; ++$row) {
    $objPHPExcel->getActiveSheet()
        ->getRowDimension($row)
            ->setOutlineLevel(2)
            ->setVisible(false)
            ->setCollapsed(true);
}
for ($row = 6; $row <= 8; ++$row) {
    $objPHPExcel->getActiveSheet()
        ->getRowDimension($row)
            ->setOutlineLevel(3)
            ->setVisible(false)
            ->setCollapsed(true);
}
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • And how about the expand and collapse icon, can we define our custom icon? – jones Feb 20 '16 at 06:22
  • 1
    I'm not aware that the icon can be changed in MS Excel itself (if you know that it can, perhaps you can point to some reference explaining how); it certainly can't be changed in PHPExcel – Mark Baker Feb 20 '16 at 09:08
  • 2
    Thank you Mark. This example made me realize that the order you set levels in is important. Smaller level should be set before the bigger one. Otherwise the folding won't work. – Your Common Sense Jan 18 '17 at 09:40