php excel html,PHPExcel - Display each sheet on HTML output

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值