如何使用图表/图表合并Excel中的多个工作簿

时间:2017-11-14 09:40:01

标签: php excel phpexcel

我有两个不同的Excel文件(工作簿),一个有2张,另一个有3个,通过使用PHP Excel库的PHP代码,我设法将所有这些组合在一个文件中,并且能够制作一个包含5张的文件,所有数据&表很好,但没有任何饼图和&图(其空白)。 如何将工作簿与图表和图表相结合?的曲线图。

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);

1 个答案:

答案 0 :(得分: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);