问题描述
|
使用codeigniter导出MS word文档有关如何编码的任何想法或教程?谢谢
解决方法
尝试这个:
header(\"Content-Type: application/vnd.ms-word\");
header(\"Expires: 0\");
header(\"Cache-Control: must-revalidate,post-check=0,pre-check=0\");
header(\"Content-disposition: attachment; filename=\\\"mydocument_name.doc\\\"\");
$output = $this->load->view(\"myreport\",$mydata);
echo $data;
exit;
, 您可以尝试使用Excel和Word导出数据
首先你做控制器
这样的
<?php if(!defined(\'BASEPATH\')) exit(\'No direct script access allowed\');
class Data extends CI_Controller
{
public function index()
{
$this->load->view(\'data_page_view\');
}
public function toExcel()
{
$this->load->view(\'spreadsheet_view\');
}
}
在这样的视图中放置您要下载的链接
<a href=\'data/toExcel\'>Export Data</a>
这可能是您对Excel数据的看法
<?php
header(\"Content-type: application/octet-stream\");
header(\"Content-Disposition: attachment; filename=exceldata.xls\");
header(\"Pragma: no-cache\");
header(\"Expires: 0\");
?>
<table border=\'1\'>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Important info</td>
</tr>
<tr>
<td>Nadeem</td>
<td>Ijaz</td>
<td>Nothing really...</td>
</tr>
</table>
这个代码用于单词数据
<?php
header(\"Content-Type: application/vnd.ms-word\");
header(\"Expires: 0\");
header(\"Cache-Control: must-revalidate,pre-check=0\");
header(\"Content-disposition: attachment; filename=\\\"worddata.doc\\\"\");
?>
<table border=\'1\'>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Important info</td>
</tr>
<tr>
<td>Nadeem</td>
<td>Ijaz</td>
<td>Nothing really...</td>
</tr>
</table>