简体   繁体   中英

Apply Effect same like xls or xlsx in csv using phpExcel

I am Exporting reports to csv and xls using PhpExcel. I can see the effects like color, Grouping, Width, Wraptext in cell, Font style, Font size, Bold etc.... in the xls format but when I pass this to csv writer object then data are properly placed in cells but no effects are applying in csv. I am using below code for export to csv.

I have tried with 2 different ways but the result was the same

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');

and another

$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);


$objWriter->setDelimiter(',');
$objWriter->setEnclosure('');
$objWriter->setLineEnding("\r\n");
$objWriter->setSheetIndex(0);

header('Content-type: text/csv');
header('Content-Disposition: attachment;filename="export.csv"');
header('Cache-Control: max-age=0');

$objWriter->save('php://output');

That's because CSV files only store data, not style.... you simply cannot store the fact that a block of text should be bold or fixed width of wrapping or even merged cells in a csv file. PHPExcel can't change that, it's just the way CSV files are, and why you need to use another format if you do want styling in your output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM