Recently i have used phpExcel library to generate reports in excel format in cakephp. Every thing is working fine except pivot Tables.
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();
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 ?
Here's how to create a PivotTable by using an existing external data connection: Click any cell on the worksheet. Click Insert > PivotTable. In the Create PivotTable dialog box, click From External Data Source.
To clone this PivotTable, navigate to PivotTable Tools Options→Select→Entire PivotTable (Figure 2). Click a cell in the same worksheet or create a new worksheet and hit ENTER. The PivotTable will now be copied to it's new location. Take note this is the only way to copy PivotTable.
As long as the tables are related, you can create your PivotTable by dragging fields from any table to the VALUES, ROWS, or COLUMNS areas.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With