namespace app\admin\controller;
use app\admin\model\TMatching as TMatchingModel;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use think\Exception;
use think\facade\Db;
class TMatching extends Base { set_time_limit(0);
ini_set('memory_limit', '252M'); // 开启事务 Db::startTrans(); try {
request->post();","marks":[]}]}],"state":{}}]'> options = [];
this->request->file('file');
this->request->post();
f (!$file) {
throw new Exception("文件出错!");
} file->getOriginalExtension();
if (!in_array($suffix, ['xlsx', 'xls'])) {
throw new Exception("文件只允许上传 ExEcl 表格文件!");
}
file->getPathName();
$reader = IOFactory::createReader('Xlsx');
if (!file_path)) {
/** @var Xls $objRead */
$reader = IOFactory::createReader('Xls');
}
if (!empty(options) && !reader->setReadDataOnly(true)) {
throw new Exception("获取文件数据失败!");
}
reader->load($file_path);
obj->getSheet($sheet);
/* 获取总行数 - 文件底部多余制表行*/
currSheet->getHighestRow();
if ($rowTotal > 5000) {
throw new Exception("文件条数超过上传限制,请分割文件后重新尝试上传!");
}
if ($rowTotal <= 0) {
throw new Exception("文件数据不能为空,请重新上传!");
}
/* 获取总列数 */
currSheet->getHighestColumn();
highestColumn);
if ($highestColumnIndex >= 40) {
throw new Exception("文件列数超过可上传范围,请分割文件后重试!");
}
currSheet->rangeToArray('A1:' . $highestColumn . 1, NULL, TRUE, FALSE);
//过滤表头数组 //验证文件表头是否符合条件
this->checkHeader($headings);
if ($checkHead != '') {
throw new Exception($checkHead);
}
$rowInfo = [];
for (row <= row++) {
// currSheet->getCellByColumnAndRow(1, $row)->getValue();
currSheet->rangeToArray('A' . highestColumn . $row, NULL, TRUE, FALSE);
// row] = array_combine(rowData[0]);
if (array_combine(rowData[0]) == false) {
continue;
} else {
row] = array_combine(rowData[0]);
}
}
///------------------------------
unset($rowData);
}
}