使用codeigniter导出MS word文档?

时间:2011-05-30 05:06:20

标签: codeigniter ms-word

使用codeigniter导出MS word文档任何关于如何编码的想法或教程?感谢

2 个答案:

答案 0 :(得分:5)

试试这个:

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;

答案 1 :(得分:0)

您可以尝试使用excel和单词导出数据

首先您要成为控制器 像这样

<?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, post-check=0, 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>