Abhijeet Sharma
Abhijeet Sharma

Reputation: 183

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 ?

Upvotes: 7

Views: 11275

Answers (1)

svrnm
svrnm

Reputation: 1059

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

Upvotes: 1

Related Questions