我将我硬盘中存在的Excel文件转换为HTML表格。 我的“showAction”很棒!使用 PHPExcel 1.8 , symfony 2.5 & PHP 5.3.13
我只想要显示前14列。 我要做一个过滤器。
我的ReadFilter
课程:
class MyReadFilter implements PHPExcel_Reader_IReadFilter {
public function __construct($fromColumn, $toColumn) {
$this->columns = array();
$toColumn++;
while ($fromColumn !== $toColumn) {
$this->columns[] = $fromColumn++;
}
}
public function readCell($column, $row, $worksheetName = '') {
if (in_array($column, $this->columns)) {
return true;
}
return false;
}
}
我的DefaultController中的showAction()
函数:
public function showAction()
{
$ami = glob('path/to/directory.{xlsx,xls,xlsm,xlsm.ink}', GLOB_BRACE);
$filterSubset = new MyReadFilter('A', 'N');
$objReader = \PHPExcel_IOFactory::createReaderForFile($ami[0]);
$objReader->setReadFilter($filterSubset);
$objPHPExcel = $objReader->load($ami[0]);
$objPHPExcel->setActiveSheetIndex(0);
$writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, "HTML");
$writer->generateStyles();
$writer->generateSheetData();
return $this->render('MyBundle:Default:testexcel.html.twig', array(
'excelHtml'=>$writer,
'stylesExcel'=>$writer,
));
}
问题是,空白列('O','P','Q')
<td class="column14"> </td>
<td class="column15"> </td>
仍在出售.. 有没有办法完全隐藏它们?
非常感谢! @Mark Baker