Well, I have a page with links to reports. Whenever somebody clicks on one report, they can download the excel file. However, sometimes there are no fields to make a report;
This way it works`
if ($result_array) to_excel($result_array->result_array(), $xls,$campos); else { echo ""; echo ""; }`