PHPExcel-从HTML表创建电子表格吗? [英] PHPExcel - Create spreadsheet from HTML table?

查看:95
本文介绍了PHPExcel-从HTML表创建电子表格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的报告系统,该系统可以输出HTML或导出到Excel.我已经掌握了通过Codeigniter视图成功创建HTML表的方法,但是我想知道是否有什么方法可以重用该视图来创建Excel导出,而不是手动执行,因此我必须进行更新每当我想对报告进行更改时,它都会在两个地方显示.

I'm trying to create a simple reporting system, which can output either HTML or export to Excel. I have got it to create a HTML table successfully through a Codeigniter view but I want to know if there's any way I can re-use that view to create the Excel export, rather than doing it manually, as I'll then have to update it in two places every time I want to make a change to the report.

任何建议表示赞赏.

谢谢.

推荐答案

这似乎可行:

// Load the table view into a variable
$html = $this->load->view('table_view', $data, true);

// Put the html into a temporary file
$tmpfile = 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); 

// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');

// Delete temporary file
unlink($tmpfile);

这篇关于PHPExcel-从HTML表创建电子表格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆