javascript - 想要通过在 codeigniter 中将数据导出到 Excel 工作表来设置表格边框

标签 javascript php mysql codeigniter

我在设置表格边框时遇到问题。

当我从 Excel 工作表导出表格时,我得到的值没有边框。

我想修复表格的边框,但它显示错误。

<div class="dvData">
  <table>
    <thead>
      <tr>
        <th>Customer Name</th>
        <th>Email Id</th>
        <th>Mobile Number</th>
        <th>Residential Address</th>
        <th>Temporary Address</th>
        <th>Company name</th>
        <th>Company type</th>
        <th>Bank Name</th>
        <th>Branch Name</th>

      </tr>
    </thead>
    <tbody>
      <?php foreach ($results as $result) { ?>
      <tr>
        <td>
          <?php echo $result->first_name;?></td>
        <td>
          <?php echo $result->email;?></td>
        <td>
          <?php echo $result->phone_num;?></td>
        <td>
          <?php echo $result->address1;?></td>
        <td>
          <?php echo $result->address2;?></td>
        <td>
          <?php echo $result->company_name;?></td>
        <td>
          <?php echo $result->customer_type;?></td>

      </tr>

      <?php } ?>

    </tbody>
  </table>
</div>

这是我的脚本代码:

jQuery(document).ready(function() {

  $(".dvData").hide();
  EditableTable.init();

  $("#btnExport").click(function (e) {
    window.open('data:application/vnd.ms-excel,' + $('.dvData').html());
    e.preventDefault();
  });
});

这是 php 代码:

<input type="button" class="btn btn-info pull-right" id="btnExport" value=" Export" />

如果不设置边框,我会得到这样的输出..引用 noborder.png 表包含没有边框的数据。

当我将边框值设置为表时,得到的输出如下所示.. border.png

enter image description here ] 2

<table border="1" width="1000px" cellspacing="0" cellpadding="0">

最佳答案

请创建此文件,假设为export.php:

                    <?php
                         header("Content-type: application/vnd-ms-excel");
                         header("Content-Disposition: attachment; filename=listing-export.xls");
                    ?>
                    <table border="1">
                    <thead>
                          <tr>
                              <th>Customer Name</th>
                              <th>Email Id</th>
                              <th>Mobile Number</th>
                              <th>Residential Address</th>
                              <th>Temporary Address</th>
                              <th>Company name</th>
                              <th>Company type</th>
                              <th>Bank Name</th>
                              <th>Branch Name</th>

                          </tr>
                          </thead>
                          <tbody>
                          <?php

                               foreach ($results as $result)
                               {

                               ?>
                          <tr>
                               <td><?php echo $result->first_name;?></td>
                               <td><?php echo $result->email;?></td>
                               <td><?php echo $result->phone_num;?></td>
                               <td><?php echo $result->address1;?></td>
                               <td><?php echo $result->address2;?></td>
                               <td><?php echo $result->company_name;?></td>
                               <td><?php echo $result->customer_type;?></td>

                          </tr>

                           <?php
                               }
                               ?>

                          </tbody>
                      </table>

然后制作其他文件,例如 do_export.php 和代码如下:

<script>
   function exportfile()
   {
       var export_file = window.open("export.php","", "left=0,top=0,width=500,height=300,toolbar=0,scrollbars=1,status=0");
       export_file.focus(); 
   }
 </script>
 <input type="Button" value="Export" onclick="exportfile()" />

制作完上述两个文件后,请运行第二个文件(do_export.php)并单击“导出”按钮。

谢谢...

关于javascript - 想要通过在 codeigniter 中将数据导出到 Excel 工作表来设置表格边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138587/

相关文章:

asp.net - 如何向 Ajax Slider 控件添加不同的值?

javascript - 通过 jquery 或 javascript 限制复选框检查

php - 简单查询中的 MySQL 语法错误

mysql - 有利于复制 mysql 表以分派(dispatch)过载

javascript - 为什么 String(null) 有效?

javascript - 使用 jquery 将所有图像包装在 html 字符串中

php - 寻找可靠的方法来了解我的手机是否在家

php - 在 Apache 上的 PHP 线程之间共享数据

php - 如何从两个表中提取帖子的用户信息?

MySQL 触发器内的日期差异检查