Hi Lando212,
I worked on the same requirement yesterday.
My testing code in Laravel 5.4:
Route::get('/xls', function() {
//this works (native PHPExcel), it does not work with the maatwebsite object:
$template = base_path().'/excel_templates/report.xlsx';
$ReadObj = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $ReadObj->load($template);
$sheet = $objPHPExcel->getActiveSheet();
$sheet->getCell('B2')->setValue('Reinier');
$sheet->getCell('B3')->setValue('Bastiaan');
$sheet->getCell('G7')->setValue('Same text');
$objPHPExcel->setActiveSheetIndexByName('data');
$sheet = $objPHPExcel->getActiveSheet();
$sheet->getCell('B2')->setValue('DATA');
$sheet->getCell('B3')->setValue('More information here');
$sheet->getCell('G7')->setValue('Say hi');
$writeObj = new PHPExcel_Writer_HTML($objPHPExcel);
//to do: define in system vars the sheet names to report to the customer
//$writeObj->writeAllSheets();
//$output = $writeObj->generateHTMLHeader();
$output = "Here is a first line of text
";
$writeObj->setSheetIndex(0);
$output .= $writeObj->generateStyles(true); // write
$output .= $writeObj->generateSheetData(); //$writeObj->save('php://output');
$output .= "Another line of text
";
$writeObj->setSheetIndex(1);
//$output .= $writeObj->generateStyles(true); // write
$output .= $writeObj->generateSheetData();
//$writeObj->save('php://output');
$output .= "This is the last line of text";
// $output = htmlspecialchars($output);
//$output .= $writeObj->generateHTMLFooter();
return view('report.output',array('output'=> $output));
});
I have this issue to resolve: the generateStyles(true) seems to use the style of the SheetIndex(0) (the first), the second generateStyles() does not take the formatting of the second sheet. Furthermore, the CSS code of the master blade overrides the CSS code that in the $output.