-1

i have two different Excel files(workbook), one have 2 sheets and another have 3, through PHP code using PHP Excel library , i managed to combine all these in one file and able to make one file with 5 sheets, all the data & table are fine , but there are no any pie charts & graphs( its blank). How can i combine workbook along with charts & graphs.

include ("PHPExcel.php");

$inputFileType1 = 'Excel2007';
$inputFileName1 = 'a.xlsx';
$inputFileType2 = 'Excel2007';
$inputFileName2 = 'b.xlsx';
$outputFileType = 'Excel2007';
$outputFileName = 'c.xlsx';

 // Load the first workbook (an xlsx file)
$objPHPExcelReader1 = PHPExcel_IOFactory::createReader($inputFileType1);
$objPHPExcelReader1->setIncludeCharts(TRUE);

$objPHPExcel1 = $objPHPExcelReader1->load($inputFileName1);

// Load the second workbook (an xls file)
$objPHPExcelReader2 = PHPExcel_IOFactory::createReader($inputFileType2);
$objPHPExcelReader2->setIncludeCharts(TRUE);
$objPHPExcel2 = $objPHPExcelReader2->load($inputFileName2);

// Merge the second workbook into the first
$objPHPExcel2->getActiveSheet()->setTitle('Unique worksheet name');
$objPHPExcel1->addExternalSheet($objPHPExcel2->getActiveSheet());

 // Save the merged workbook under a new name (could save under the original 
 name)
// as an xls file
$objPHPExcelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1,$outputFileType);
$objPHPExcelWriter->save($outputFileName);
Sooraz
  • 113
  • 7
  • Possible of Duplicate: https://stackoverflow.com/questions/11545974/merge-excel-files-using-php – jvk Nov 14 '17 at 10:03

1 Answers1

0
$inputFileType1 = 'Excel2007';
$inputFileName1 = 'inputData1.xlsx';
$inputFileType2 = 'Excel5';
$inputFileName2 = 'inputData2.xls';
$outputFileType = 'Excel5';
$outputFileName = 'outputData.xls';

// Load the first workbook (an xlsx file)
$objPHPExcelReader1 = PHPExcel_IOFactory::createReader($inputFileType1);
$objPHPExcel1 = $objPHPExcelReader1->load($inputFileName1);

// Load the second workbook (an xls file)
$objPHPExcelReader2 = PHPExcel_IOFactory::createReader($inputFileType2);
$objPHPExcel2 = $objPHPExcelReader2->load($inputFileName2);

// Merge the second workbook into the first
$objPHPExcel2->getActiveSheet()->setTitle('Unique worksheet name');
$objPHPExcel1->addExternalSheet($objPHPExcel2->getActiveSheet());

// Save the merged workbook under a new name (could save under the original name)
// as an xls file
$objPHPExcelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1,$outputFileType);
$objPHPExcelWriter->save($outputFileName);
jvk
  • 2,133
  • 3
  • 19
  • 28
  • actually both the files i have is in .xlsx format so Excel2007 should be used in filetype i think, i tried this , same result no charts and graphs – Sooraz Nov 14 '17 at 10:22