I am trying to generate an excel file with the extension .xlsx from the code below. I am able to download the file very well but when I open it with excel sheet, I receive t
That error is just telling you that there was no buffer to delete. To avoid it just use:
if (ob_get_contents()) ob_end_clean();
(check if there's an active output buffer) or:
if (ob_get_length()) ob_end_clean();
(checks if there's a non empty string in the buffer) as suggested by @Venu.
also you are calling ob_end_clean(); two times there. And that only works with stackable buffers. From the PHP manual:
This function discards the contents of the topmost output buffer and turns off this output buffering.
Are you sure you don't want to just use ob_clean()?