Read only specific sheet

前端 未结 4 1400
面向向阳花
面向向阳花 2021-01-01 17:26

I am trying to read just one sheet from an xls document and I have this:

 $objPHPExcel = $objReader->load(\'daily/\' . $fisierInbound);
 $objWorksheet = $         


        
4条回答
  •  無奈伤痛
    2021-01-01 18:01

    As described in the PHPExcel User Documentation - Reading Spreadsheet Files document in the /Documentation folder (section 5.2. entitled"Reading Only Named WorkSheets from a File"):

    If you know the name of the sheet that you want to read.

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

    If you don't know the name of the worksheet in advance, you can get a list of all worksheets before loading the file

    $inputFileType = 'Excel5'; 
    $inputFileName = './sampleData/example1.xls'; 
    
    /**  Create a new Reader of the type defined in $inputFileType  **/ 
    $objReader = PHPExcel_IOFactory::createReader($inputFileType); 
    /**  Read the list of worksheet names and select the one that we want to load  **/
    $worksheetList = $objReader->listWorksheetNames($inputFileName)
    $sheetname = $worksheetList[0]; 
    
    /**  Advise the Reader of which WorkSheets we want to load  **/ 
    $objReader->setLoadSheetsOnly($sheetname); 
    /**  Load $inputFileName to a PHPExcel Object  **/ 
    $objPHPExcel = $objReader->load($inputFileName); 
    

提交回复
热议问题