|
<?php
namespace app\index\model;
require_once(VENDOR . '\PHPExcel\IOFactory.php');
class Sales
{
private $excel;
private $sheet_namas;
private $first_sheet_name;
public $data;
public function __construct()
{
$this->excel = \PHPExcel_IOFactory::load(DB . DS . "2020xsjl.xls");
$this->getFirstSheets();
}
/**
* 获取所有工作表名
*/
private function getSheetNames()
{
$this->sheet_namas = $this->excel->getSheetNames();
$this->first_sheet_name = $this->sheet_namas[0];
}
/**
* 获取第一个 sheet 的所有数据
*/
private function getFirstSheets()
{
// 获取所有工作表名
$this->getSheetNames();
//根据表名切换当前工作表
$this->excel->setActiveSheetIndexByName($this->first_sheet_name);
//得到当前工作表对象
$curSheet = $this->excel->getActiveSheet();
// //获取当前工作表最大行数
// $rows = $curSheet->getHighestRow();
// //获取当前工作表最大列数,返回的是最大的列名,如:B
// $cols = $curSheet->getHighestColumn();
// //将当前工作表名当键,内容为值存入数组
// $data = [];
// //大写字母A的ASCII值是65 A-Z对应65-90
// // for($j = 'A'; $j <= $cols; $j++ ){
// // for($k = 1; $k <= $rows; $k++){
// // $key = $j.$k;
// // $value = $curSheet->getCell($key)->getValue();
// // $data[$key] = $value;
// // }
// // } 结果为一维数组
// 调用 PHPExcel_Worksheet toArray 方法
$this->data = $curSheet->toArray();
}
}
|