0

我使用 Symfony 2.5 使用 PHPExcel (PHPspreadsheet) 将 excel 文件转换为 HTML 表

我正在尝试将过滤器设置为仅加载范围 ('A','N') ,即前 13 列。不工作..

我也在尝试设置“N”列的宽度。不工作..

当我转储列的宽度值是正确的..

我可以增加列宽但不能减少它们..

看起来单元格内的文本正在自动定义单元格的宽度..

这是我的控制器:

       public function showClientAction($client)
    {

        $excel = glob(''.path.'\\'.path.'\\filename_' .$client.'.{xlsx,xls,xlsm,xlsm.ink}', GLOB_BRACE);

        $filterSubset = new \PHPExcel_Reader_DefaultReadFilter(1,1000,range('A','N'));
        $objReader = \PHPExcel_IOFactory::createReaderForFile($excel[0]);
        $objReader->setReadFilter($filterSubset);
        /**  Read the list of worksheet names and select the one that we want to load  **/
        $worksheetList = $objReader->listWorksheetNames($excel[0]);
        $sheetname = $worksheetList[0];

        /**  Advise the Reader of which WorkSheets we want to load  **/
        $objReader->setLoadSheetsOnly($sheetname);

        $objPHPExcel = $objReader->load($excel[0]);

        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn('13')->setAutoSize(false);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn('13')->setWidth(2.5);

// OUTPUT is : int (13) applied correctly
        var_dump($objPHPExcel->getActiveSheet()->getColumnDimensionByColumn('13'));

        $writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, "HTML");
        $writer->generateSheetData();
        $writer->generateStyles();

        return $this->render('SocPerfclientBundle:Default:testexcel.html.twig', array(
            'excelHtml'=>$writer,
            'stylesExcel'=>$writer,
            'client'=>$nom_client
        ));
    }

我的过滤器:

    class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
{
    public $_startRow = 0;
    public $_endRow   = 0;
    public $_columns  = array();

    /**  Get the list of rows and columns to read  */
    public function __construct($startRow, $endRow, $columns) {
        $this->_startRow = $startRow;
        $this->_endRow   = $endRow;
        $this->_columns  = $columns;
    }

    public function readCell($column, $row, $worksheetName = '') {
        // Only read the rows and columns that were configured
        if ($row >= $this->_startRow && $row <= $this->_endRow) {
            if (in_array($column,$this->_columns)) {
                return true;
            }
        }
        return false;
    }
}

我的观点 :

{{ excelHtml.generateSheetData | raw }}
{{ stylesExcel.generateStyles | raw }}

这里是一个截图 html 视图:我们可以看到“RCA”列仍然具有初始宽度..我的 setWidth 没有应用..

如果我用更短的词更改链接,例如:yes.docx,则该列会减少。

在此处输入图像描述

4

0 回答 0