Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Possible To Generate Or Clone Pivot Tables Using PhpExcel Library?

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 ?

like image 659
Abhijeet Sharma Avatar asked Sep 02 '14 16:09

Abhijeet Sharma


People also ask

Is it possible to create a PivotTable from an external data source in Excel?

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.

Can you clone a PivotTable?

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.

Can we create PivotTable using multiple source tables?

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.


1 Answers

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

like image 134
svrnm Avatar answered Sep 28 '22 18:09

svrnm