是否可以使用 PhpExcel 库生成或克隆数据透视表

时间:2023-03-21
本文介绍了是否可以使用 PhpExcel 库生成或克隆数据透视表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我使用 phpExcel 库在 cakephp 中生成 excel 格式的报告.除了数据透视表外,一切正常.

Recently i have used phpExcel library to generate reports in excel format in cakephp. Every thing is working fine except pivot Tables.

我正在使用主 Excel 工作表(其中包含数据透视表)来克隆/生成其他 Excel 工作表.在新生成的工作表中,其他信息看起来不错,但未生成数据透视表(仅显示标题上的名称.没有过滤器选项).这是我正在使用的代码.

I am using a master excel sheet (Which contain pivot table) to clone/generate other excel sheet. In newly generated sheet other information is looking fine but pivot table is not being generated (only names on header are being display. There is no filter options). Here is the code i am using.

        $filename = WWW_ROOT."files/master_report_template/compliance_workflow_master_template.xlsx";
        $reportFileName = WWW_ROOT."files/documents/reports/compliance_workflow_template.xlsx";
        $this->PhpExcel->loadWorksheet($filename); 
        $this->PhpExcel->getActiveSheet()->setCellValue('B1',$this->request->data['fromDate']);
        $this->PhpExcel->getActiveSheet()->setCellValue('B2',$this->request->data['toDate']);
        $this->PhpExcel->getActiveSheet()->setCellValue('B3',date('D-M-y'));
        $row=6;
        foreach($repostData as $rows)
        {
            $col = 0;
            foreach($rows as $key =>$value)
            {   
                $this->PhpExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $value);
                $col++;
            }
            $row++;
        }
        $this->PhpExcel->save($reportFileName);
        $this->PhpExcel->output(); 

我认为生成的 excel 表将是 Master excel 表的克隆,但两者都不相同(由于数据透视表).是否有任何好的教程或文档来生成数据透视表?

I thought that generated excel sheet would be the clone of Master excel sheet but both are not same (due to pivot tables). Is there any good tutorial or documentations to generate pivot table ?

推荐答案

虽然这是一个老问题,但我想给出一个答案:几个月前我也有同样的问题,最后决定我需要做我的自己的实现(所以这是自我广告..)

Albeit this is an old issue, I'd like to give an answer: I had the same issue some months ago and finally decided that I need to do my own implementation (so this is self-advertisement..)

此解决方案远非完美 - 因为我可能是唯一使用它的人 - 但它完全按照您的描述执行:将原始数据写入一张主文件"中,允许您创建报告:

This solution is far from perfect - since I'm maybe the only person using it - but it is doing exactly what you describe: Writing raw data into one sheet of a "master file" allowing you to create reports:

https://github.com/svrnm/exceldatatables

这篇关于是否可以使用 PhpExcel 库生成或克隆数据透视表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:CakePHP:致命错误:允许的内存大小为 536870912 字节已 下一篇:如何通过未按约定命名的字段关联 CakePHP 中的模

相关文章

最新文章