2017-06-06 90 views
0

我使用PHPExcel Reader函數將excel文件轉換爲HTML表格。PHPExcel內存錯誤

我得到這個錯誤:致命錯誤:內存(分配1827405824)(試圖分配106個字節)

我已經改變了我對memory_limit的2048M在我的php.ini文件..

仍然收到錯誤..

那麼我怎樣才能只加載我的Excel文件的第一張,它也許可以解決我的問題?

$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, 
    )); 
} 

var_dump($sheetname);輸出是很好的,它的偉大工程!

但我怎麼能確定只加載第一張?

它不似乎是一個更快的加載.. * scuze我的英語..

回答

1

So How can i only load the first sheet of my Excel file, it can maybe solve my issue ?

直起PHPExcel Documentation

$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來獲取工作表名稱列表,而無需加載整個文件。

+0

是否可以加載和顯示我的Excel文件中的過濾器,並通過HTML表格將其轉換爲下拉按鈕? –