使用 codeigniter 导出 MS Word 文档?

发布于 2024-11-10 09:56:12 字数 54 浏览 1 评论 0原文

使用 codeigniter 导出 MS Word 文档 关于如何编码有任何想法或教程吗?谢谢

exporting MS word documents using codeigniter any idea or tutorial on how to code? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖树树初阳… 2024-11-17 09:56:12

试试这个:

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;

Try this:

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;
樱花落人离去 2024-11-17 09:56:12

您可以先尝试此方法导出 E​​xcel 和 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>

和 Word 数据的代码

    <?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> 

you may try this for excel and word export data

first you make controller
this like this

<?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');
  }
}

put a link from where you want to download in a view like this

<a href='data/toExcel'>Export Data</a>

and this may your view for excel data

    <?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>

and this code for word data

    <?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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文