我使用PHPExcel Reader功能将excel文件转换为HTML表格。
我收到此错误:致命错误:内存不足(已分配1827405824)(尝试分配106个字节)
我在php.ini文件中将memory_limit更改为2048M ..
仍然收到错误..
那么我怎么才能加载我的Excel文件的第一张,它可以解决我的问题?
R
编辑:
我这样做:
$excel = glob(''.$test.'\\'.$client.'.{xlsx,xls,xlsm,xlsm.ink}',GLOB_BRACE);
$filterSubset = new \PHPExcel_Reader_DefaultReadFilter('A','N');
$objReader = \PHPExcel_IOFactory::createReaderForFile($excel[0]);
$objReader->setReadFilter($filterSubset);
$objPHPExcel = $objReader->load($excel[0]);
## THIS DOESNT WORK ?! ##
$objPHPExcel->setActiveSheetIndex(1);
$links = $objPHPExcel->getActiveSheet()->getHyperlinkCollection();
var_dump($links);
foreach ($links as $link){
$url = $link->getUrl();
$url = str_replace('file','mnt', $url);
$link->setUrl($url);
}
$writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, "HTML");
$writer->generateStyles();
$writer->generateSheetData();
public function showClientAction($client)
{
$excel = glob(''.$path'.{xlsx,xls,xlsm,xlsm.ink}', GLOB_BRACE);
$filterSubset = new \PHPExcel_Reader_DefaultReadFilter('A','N');
$objReader = \PHPExcel_IOFactory::createReaderForFile($excel[0]);
$objReader->setReadFilter($filterSubset);
$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]);
var_dump($sheetname);
$writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, "HTML");
$writer->generateStyles();
$writer->generateSheetData();
return $this->render('MonextPerfclientBundle:Default:testexcel.html.twig', array(
'excelHtml'=>$writer,
'stylesExcel'=>$writer,
));
}
输出是好的,它很棒!
但我怎么能确定只加载第一张?
这似乎不是一个更快的装载.. *保持我的英语..
答案 0 :(得分:1)
那么我怎么才能加载我的Excel文件的第一张,它可以解决我的问题?
$inputFileType = 'Excel5';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #2';
/** Create a new Reader of the type defined in $inputFileType **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Advise the Reader of which WorkSheets we want to load **/
$objReader->setLoadSheetsOnly($sheetname);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName);
如果您不知道第一张工作表的名称,那么PHPExcel会提供helper method来获取工作表名称列表,而无需加载整个文件。