我使用PHPExcel将excel文件转换为HTML表格 (PHPspreadsheet)与Symfony 2.5
我正在尝试将过滤器设置为仅加载前13列的范围('A','N')。 无法正常工作 ..
我也试图设置'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,则列会减少。