問題描述
最近我使用 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模板網!