克隆现有工作表并在其中添加信息

时间:2016-03-17 14:02:51

标签: php phpexcel

我的1文件中有2张。我需要打开工作表编号foreach并使用数据克隆它,就像我Message: Workbook already contains a worksheet named 'otchet-shablon'. Rename this worksheet first. 循环一样。

{
    "collection": [
        {
        "nr": "99990655",
        "machine": "Test A"
        },
        {
        "nr": "123435546",
        "machine": "Test B"
        }
        ]
}

1 个答案:

答案 0 :(得分:1)

重命名克隆的工作表(它仍然与原始名称相同,因为它是克隆) 之前 将其添加到PHPExcel对象

$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet1 = clone $activeSheet;

$activeSheet1->setTitle('New worksheet title')

$objPHPExcel->addSheet($activeSheet1);