在实际项目中常常会读取文件或表格中的数据,本篇文章简要介绍了如何使用PHPExcel读取Excel表格中的数据。
首先需要获取PHPExcel对象,即,$this->objPHPExcel = new SfLib_PHPExcel($this->sourceFile);
public function __construct($file = null)
{
parent::__construct();
if (!empty($file))
{
$this->file = $file;
$this->fileObj = $this->load($file);
}
}
public function load($file)
{
try
{
$inputFileType = PHPExcel_IOFactory::identify($file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
// $objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
$this->file = $file;
$this->fileObj = $objPHPExcel;
return $objPHPExcel;
} catch (PHPExcel_Reader_Exception $e)
{
throw new SfL