簡體   English   中英

設置列寬Excel導出PHP

[英]Set column width Excel export php

我有一個使用php進行excel導出的表格。現在代碼運行良好,但所有列似乎都相同width.I想設置列寬,但是我該如何設置呢?這是我的代碼

<form style="display:none" id="sendtable" action="<?php echo PRODUCTS . 'downloadexcel' ?>" method="post">
<input type="button" name="Export Excel"
     value="Export Excel" onclick="callexports();"/>
<div id="tabledata">
<html>
<head>
<style>
  table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
  }
  th, td {
    padding: 5px;
    text-align: left;
  }
  table#t01 {
    width: 100%;    
    background-color: #f1f1c1;
  }
</style>
</head>
<body>
  <table style="width:100%">
    <!-- Column 1 -->
    <colgroup width="80%" style="background-color: green;">
    <!-- Column 2 -->
    <colgroup width="80%" style="background-color: red;">
  <tr>
    <th>#</th>
    <th>Action Items</th>
    <th>Assigned to</th>
    <th>Start date</th>
    <th>End date date</th>
  </tr>
  <tr>
    <?php
    if (isset($this->getallactionitems)):
       $i = 1;
       foreach ($this->getallactionitems as $details):
     ?>
     <td><?php echo $i; ?></td>
     <td style="width: 80%;">
       <?php echo $details['Actions']?></td>
     <td><?php echo $details['Assigned_to']  ?></td>
     <td><?php echo $details['Start_date']  ?></td>
     <td><?php echo $details['End_date']  ?></td>
  </tr>
     <?php $i++ ?>
     <?php endforeach;
        endif; ?>
  </tr>
</table>
<br>
</body>
<input type="hidden" name="tableval" id="tableval" />
</form>

功能下載:

public function downloadexcel() {
        $filename = "Actionitems" . time(); //File Name
        $file_ending = "doc";
//header info for browser
        header("Content-type:application/vnd.msword");
//    header("Expires:0");//no cache
//    header("Cache-Control:must-revalidate,post-check=0,pre-check=0");//no cache
//    header("content-disposition:attachment;filename=sampleword.xlxs");
        header("Content-Type: application/xls");
        header("Content-Disposition: attachment; filename=$filename.xls");
        header("Pragma: no-cache");
        header("Expires: 0");
        Echo $_REQUEST['tableval'];
}

哪個工作正常..但是我想使用此代碼設置B列寬。現在所有列寬似乎都相同。如何設置列寬?請幫幫我。

您應該簽出此軟件包,它非常適合使用excel文件,並且文檔很好。 您不必構建自己的excel文件,只需將數據作為數組傳遞給庫。

https://packagist.org/packages/phpoffice/phpexcel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM