增加/自定义数据表中的列大小excel导出

时间:2018-03-08 13:13:04

标签: php excel datatables yii2

在使用数据表导出无效时,我一直在尝试自定义/增加excel中的列大小。导出时收到的数据在列中压缩,无法查看整个详细信息。

这是我在导出时获得的excel文件:

enter image description here

如何实现这一目标?

   <?php

   use yii\helpers\Html;
   use yii\grid\GridView;


    /* @var $this yii\web\View */
    /* @var $searchModel app\models\StatusSearch */
   /* @var $dataProvider yii\data\ActiveDataProvider */

   $this->title = 'Report For B2C Services';
   $this->params['breadcrumbs'][] = $this->title;
   ?>


     <script type="text/javascript" 
src="https://cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js"> 
 </script>
  <script type="text/javascript" 
  src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.6.0/jszip.js"> 
  </script>
  <script type="text/javascript" 
  src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.6.0/jszip.min.js"> 
  </script>
  <script type="text/javascript" 
  src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"> 
  </script>

<div class="table-responsive">
<table class="display nowrap" id="example1">
    <thead>
    <tr>
        <th>DEBIT ACCOUNT</th>
        <th>SOURCE NO</th>
        <th>BENEFICIARY NO</th>
        <th>TRANSACTION DATE</th>
        <th>AMOUNT</th>
        <th>RECEIPT</th>

    </tr>
    </thead>
    <tbody>
    <?php foreach($model as $block) {?>
        <tr class="gradeX">
            <td><?= $block['DEBITACCOUNT'];?></td>
            <td><?= $block['SOURCEMOBILENUMBER'];?></td>
            <td><?= $block['BENEFICIARYMOBILENUMBER'];?></td>
            <td><?= $block['TRN_DATE'];?></td>
            <td><?= $block['AMOUNT'];?></td>
            <td><?= $block['RECEIPT'];?></td>

        </tr>
    <?php }?>
    </tbody>
    <tfoot>

    </tfoot>
</table>

<?php

$script = <<< JS


 $(function () {

    $('#example1').DataTable( {
      dom: 'Bfrtip',
      "paging": true,
  "lengthChange": true,
  "searching": false,
  "ordering": true,
  "info": true,
  "autoWidth": true,
    buttons: [
       'copy', 'excel','csv', 'pdf'
    ]

} );


 });

JS;
$this->registerJs($script);
?>

1 个答案:

答案 0 :(得分:0)

这不是您的编码问题。您可以在Excel工作表中增加列大小。