majiameng /
spreadsheet-php
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * @name: 报表导入查询 |
||||
| 4 | * @Created by IntelliJ IDEA |
||||
| 5 | * @author: tinymeng |
||||
| 6 | * @file: Import.php |
||||
| 7 | * @Date: 2018/7/4 10:15 |
||||
| 8 | */ |
||||
| 9 | namespace tinymeng\spreadsheet\Gateways; |
||||
| 10 | |||||
| 11 | use PhpOffice\PhpSpreadsheet\Exception; |
||||
| 12 | use PhpOffice\PhpSpreadsheet\IOFactory; |
||||
| 13 | use tinymeng\spreadsheet\Connector\Gateway; |
||||
| 14 | use tinymeng\spreadsheet\Excel\SpreadSheet; |
||||
| 15 | use tinymeng\spreadsheet\Util\TConfig; |
||||
| 16 | |||||
| 17 | class Import extends Gateway { |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * TConfig |
||||
| 21 | */ |
||||
| 22 | use TConfig; |
||||
| 23 | /** |
||||
| 24 | * TSpreadSheet |
||||
| 25 | */ |
||||
| 26 | use SpreadSheet; |
||||
| 27 | |||||
| 28 | |||||
| 29 | /** |
||||
| 30 | * @return $this |
||||
| 31 | * @throws Exception |
||||
| 32 | */ |
||||
| 33 | public function initWorkSheet($filename='') |
||||
| 34 | { |
||||
| 35 | if(!empty($filename)){ |
||||
| 36 | $this->setFileName($filename); |
||||
| 37 | } |
||||
| 38 | $this->loadFile($this->fileName); |
||||
| 39 | //获取sheet表格数目 |
||||
| 40 | $this->sheetCount = $this->spreadSheet->getSheetCount(); |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 41 | //默认选中sheet0表 |
||||
| 42 | $this->spreadSheet->setActiveSheetIndex($this->sheet); |
||||
|
0 ignored issues
–
show
$this->sheet of type boolean|string is incompatible with the type integer expected by parameter $worksheetIndex of PhpOffice\PhpSpreadsheet...::setActiveSheetIndex().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 43 | $this->workSheet = $this->spreadSheet->getActiveSheet(); |
||||
| 44 | //获取表格行数 |
||||
| 45 | $this->rowCount = $this->workSheet->getHighestDataRow(); |
||||
| 46 | //获取表格列数 |
||||
| 47 | $this->columnCount = $this->workSheet->getHighestDataColumn(); |
||||
| 48 | //初始化所有列数组 |
||||
| 49 | $this->cellName = $this->getCellName($this->columnCount); |
||||
| 50 | return $this; |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | } |
||||
| 54 |