Phpspreadsheet: Is it posible to create pivot table using PHPSpreadsheet

Created on 7 Sep 2018  路  2Comments  路  Source: PHPOffice/PhpSpreadsheet

HI everyone ,

Please help me if its possible to create pivot tables while doing export using PHPExcel/PHPSPreadsheet.

question

All 2 comments

This looks like a support question. Please ask your support questions on StackOverflow, or Gitter.
Thank you for your contributions.

Hi,
please, ask yourself to create the few lines of code in the code below to create a PivotTable in the second sheet in integrand cells B1 to C6
I can not find examples and I am not competent enough
thank you

` //call the autoload
require 'PhpSpreadSheet/vendor/autoload.php';
//load phpspreadsheet class using namespaces
use PhpOffice\PhpSpreadsheet\Spreadsheet;
//call xlsx writer class to make an xlsx file
use PhpOffice\PhpSpreadsheet\IOFactory;

//make a new spreadsheet object
$spreadsheet = new Spreadsheet();
//get current active sheet (first sheet)
$sheet = $spreadsheet->getActiveSheet();

    //insert value
    $sheet->setCellValue('B1', 'A'); $sheet->setCellValue('C1', '1');
    $sheet->setCellValue('B2', 'A'); $sheet->setCellValue('C2', '2');
    $sheet->setCellValue('B3', 'A'); $sheet->setCellValue('C3', '3');
    $sheet->setCellValue('B4', 'B'); $sheet->setCellValue('C4', '1');
    $sheet->setCellValue('B5', 'B'); $sheet->setCellValue('C5', '2');
    $sheet->setCellValue('B6', 'B'); $sheet->setCellValue('C6', '3');

    // creat, rename and select second worksheets
    $spreadsheet->createSheet()->setTitle('Analyse');
    $spreadsheet->setActiveSheetIndex(1);

// Create pivot table???
    ????
    ????
    ????

    //set the header first, so the result will be treated as an xlsx file
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//make it an attachment so we can define filename
$filnam = 'ExtractGePi_'.date('ymdhis').'.xlsx';
header('Content-Disposition: attachment;filename='.$filnam);
//header('Content-Disposition: attachment;filename="Result.xlsx"');
//create IOFactory object
$writer=IOFactory::createWriter($spreadsheet, 'Xlsx');
//save into php output
$writer->save('php://output');

?>`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smartlara picture smartlara  路  5Comments

huichen2017 picture huichen2017  路  4Comments

cheinle picture cheinle  路  3Comments

isopen picture isopen  路  3Comments

AlexPravdin picture AlexPravdin  路  4Comments