首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置列宽Excel导出php

设置列宽Excel导出php
EN

Stack Overflow用户
提问于 2018-01-19 14:47:11
回答 1查看 1.3K关注 0票数 0

我有一个使用php.Now代码导出excel的表单,运行良好,但所有列似乎都相同宽度。我想设置列宽度,但我如何设置that.here是我的代码

代码语言:javascript
复制
<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>

函数下载:

代码语言:javascript
复制
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'];
}

我想用这个code.Now来设置B列的宽度所有的列宽看起来是一样的width.How来设置列宽?请帮助我。

EN

回答 1

Stack Overflow用户

发布于 2018-01-19 15:02:27

你应该看看这个包,它非常适合处理excel文件,并且它有很好的文档。您不必构建自己的excel文件,只需将数据作为数组传递给库即可。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48335534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档