Remove Blank Row While exporting an excel using PHP

Remove Blank Row While exporting an excel using PHP

Sometime after exporting an excel it does have space in top of the sheet. Due to this space excel workbook content format lost.

Steps to resolve this issue on Excel and CSV

Step1 – Remove whitespace form file top or before PHP open and close tag.

Step2 – Add PHP functions ob_clean(); and flush(); after php download header.

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename='Demo_excel.xlsx');
header('Cache-Control: max-age=0');

// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Last-Modified: '.gmdate('D, d M Y H:i:s') .' GMT');
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
ob_clean();
flush();

One Comment on “Remove Blank Row While exporting an excel using PHP”

  1. I like what you guys are up also. Such smart work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my web site 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *