laravel PHPExcel如何为行组设置折叠和展开?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35473034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:15:34  来源:igfitidea点击:

PHPExcel how to set collapse and expands for groups of row?

phplaravellaravel-5.1phpexcellaravel-excel

提问by jones

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.

假设我想将第 2 行到第 4 行的折叠和展开设置为一组,将第 8 行到第 12 行设置为第二组。这意味着当用户想要点击+第 1 组的展开图标时,应该可以看到 2 到 4 行,而对于第 2 组,应该可以看到 8 到 12 行。波纹管是单行的代码。

$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

另一个问题是,我们可以自己定义扩展图标而不是+图标吗?就像是这个

回答by Mark Baker

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