kohana中的PHPEXCEL导出excel显示机器代码如何清除?
我已经像这样尝试过这个代码kohana中的PHPEXCEL导出excel显示机器代码如何清除?,php,phpexcel,kohana,Php,Phpexcel,Kohana,我已经像这样尝试过这个代码 require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex()->setCellValue('A1', 'Hello world!'); $objWriter = PHPExcel_IOFactory::
require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex()->setCellValue('A1', 'Hello world!');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$this->response->body( $objWriter->save('php://output'));
$this->response->send_file(TRUE, '01simple.xls');
exit;
错误如下图所示
你能试试这个吗
require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php';
$phpExcel = new PHPExcel();
$phpExcel->getActiveSheet()->setTitle("Title of my excel");
$phpExcel->setActiveSheetIndex(0);
$phpExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$filename = "file_name";
ob_clean();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
你能试试这个吗
require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php';
$phpExcel = new PHPExcel();
$phpExcel->getActiveSheet()->setTitle("Title of my excel");
$phpExcel->setActiveSheetIndex(0);
$phpExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$filename = "file_name";
ob_clean();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
使用这种方法对我来说很有效。在一个变量中设置内容并分配。这里我提到了一个例子
require_once APPPATH.'libraries/reader/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$reportHtml = '<table cellpadding="0" cellspacing="0" class="table table-bordered" style="border:1px solid #f0f0f0;">
<thead>
<tr>
<th>Customer Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Invoice Id</th>
<th>Invoice Date</th>
<th>Due Date</th>
<th>Balance Amount</th>
<th>Total Amount</th>
</tr>
</thead>';
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $reportHtml);
// 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
header("Cache-Control: private", false);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=test_1'.time().'.xlsx');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('php://output');
unlink($tmpfile);
require_once APPPATH.'libraries/reader/PHPExcel.php';
$objPHPExcel=new PHPExcel();
$reportHtml=
客户名称
电子邮件
可移动的
发票Id
发票日期
到期日
余额
总金额
';
//将html放入临时文件中
$tmpfile=time().'.html';
文件内容($tmpfile,$reportHtml);
//将文件内容读入PHPExcel Reader类
$reader=新的PHPExcel\u reader\u HTML;
$content=$reader->load($tmpfile);
//根据需要传递给编写器并输出
标头(“缓存控制:专用”,false);
标题('Content-Type:application/vnd.openxmlformats officedocument.spreadsheetml.sheet');
标题('Content-Disposition:attachment;filename=test_1'.time()..xlsx');
标头('Cache-Control:max age=0');
$objWriter=PHPExcel_IOFactory::createWriter($content,'Excel2007');
$objWriter->save('php://output');
取消链接($tmpfile);
使用这种方法对我来说很有效。在一个变量中设置内容并分配。这里我提到了一个例子
require_once APPPATH.'libraries/reader/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$reportHtml = '<table cellpadding="0" cellspacing="0" class="table table-bordered" style="border:1px solid #f0f0f0;">
<thead>
<tr>
<th>Customer Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Invoice Id</th>
<th>Invoice Date</th>
<th>Due Date</th>
<th>Balance Amount</th>
<th>Total Amount</th>
</tr>
</thead>';
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $reportHtml);
// 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
header("Cache-Control: private", false);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=test_1'.time().'.xlsx');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('php://output');
unlink($tmpfile);
require_once APPPATH.'libraries/reader/PHPExcel.php';
$objPHPExcel=new PHPExcel();
$reportHtml=
客户名称
电子邮件
可移动的
发票Id
发票日期
到期日
余额
总金额
';
//将html放入临时文件中
$tmpfile=time().'.html';
文件内容($tmpfile,$reportHtml);
//将文件内容读入PHPExcel Reader类
$reader=新的PHPExcel\u reader\u HTML;
$content=$reader->load($tmpfile);
//根据需要传递给编写器并输出
标头(“缓存控制:专用”,false);
标题('Content-Type:application/vnd.openxmlformats officedocument.spreadsheetml.sheet');
标题('Content-Disposition:attachment;filename=test_1'.time()..xlsx');
标头('Cache-Control:max age=0');
$objWriter=PHPExcel_IOFactory::createWriter($content,'Excel2007');
$objWriter->save('php://output');
取消链接($tmpfile);
这不是机器代码,而是错误编码的文本:)这不是机器代码,而是错误编码的文本:)谢谢。我包括你的代码。结果是“无法访问此站点”,请使用此代码创建一个单独的文件。给require_一次正确的路径
,然后测试它……)谢谢你@praveen kumar。我已经看过了,但控制器不能有任何功能如何才能在phpexcel控制器。谢谢你。我包括你的代码。结果是“无法访问此站点”,请使用此代码创建一个单独的文件。给require_一次正确的路径
,然后测试它……)谢谢你@praveen kumar。我已经看过了,但控制器不能有任何功能如何在phpexcel中控制。谢谢。在kohana框架中,只有加载问题。框架外侧工作良好。请给我kohana框架代码。我知道kohana框架。我只是在谷歌上搜索一下,我得到了一些例子。我知道它是如何工作的。你只需要经历一下,谢谢你。在kohana框架中,只有加载问题。框架外侧工作良好。请给我kohana框架代码。我知道kohana框架。我只是在谷歌上搜索一下,我得到了一些例子。我知道它是如何工作的。你只要经历它