public function create_excel() { $fileName = $this->input->post('fileName'); $html = $this->input->post('report'); // load the excel library $this->load->library('excel'); // Put the html into a temporary file $tmpfile = 'assets/files/temp/' . time() . '.html'; file_put_contents($tmpfile, $html); // Read the contents of the file into PHPExcel Reader class $reader = new PHPExcel_Reader_HTML(); $content = $reader->load($tmpfile); $objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007'); // We'll be outputting an excel file header('Content-type: application/vnd.ms-excel'); // It will be called file.xls header('Content-Disposition: attachment; filename="file.xlsx"'); // Write file to the browser $objWriter->save('php://output'); // Pass to writer and output as needed // $objWriter->save('assets/files/temp/excelfile.xlsx'); // Delete temporary file unlink($tmpfile); return false; }
* * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ /** Error reporting */ error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('Europe/London'); define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />'); require_once 'Classes/PHPExcel.php'; session_start(); $tmpfile = time() . '.html'; file_put_contents($tmpfile, $_SESSION["tablaOperaciones"]); $reader = new PHPExcel_Reader_HTML(); $content = $reader->load($tmpfile); $objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007'); $objWriter->save('php://output'); unlink($tmpfile);