本文整理汇总了PHP中Excel::readSimpleUploadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Excel::readSimpleUploadFile方法的具体用法?PHP Excel::readSimpleUploadFile怎么用?PHP Excel::readSimpleUploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Excel
的用法示例。
在下文中一共展示了Excel::readSimpleUploadFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importteacher
/**
* 导入教师记录(从excel文件中),
*/
public function importteacher($sch_id = 0)
{
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_school_teacher_template.xlsx', '教师导入模板.xlsx');
exit;
}
if (!$sch_id || !SchoolModel::schoolInfo($sch_id)) {
message('学校不存在,无法导入教师!');
}
$data = array();
$data['sch_id'] = $sch_id;
while (isset($_FILES['file'])) {
$param = $_POST;
$title = array('姓名', '年级', '学科', '简介');
$col_char = array();
$rows = Excel::readSimpleUploadFile($_FILES['file'], $title, $col_char);
if (!is_array($rows)) {
$data['error'] = $rows;
break;
}
$grade_map = array_flip(C('grades'));
$subject_map = array_flip(C('subject'));
$ct_list = array();
foreach ($rows as $k => $row) {
//////////////////////////////
// 姓名0 年级1 学科2 简介3
//////////////////////////////
// 姓名
if ($row[0] == '') {
$data['error'] == $col_char[0] . ($k + 2) . ' - "姓名"不可为空';
break;
}
if (mb_strlen($row[0], 'UTF-8') > 30) {
$data['error'] = $col_char[0] . ($k + 2) . ' - "姓名"内容太长了,不可超过30个字符';
break;
}
// 年级
if ($row[1] == '') {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"不能为空';
break;
}
$row[1] = str_replace(array(',', ' ', ' ', '、', "\r\n", "\r", "\n"), ',', $row[1]);
$row['ctg_gradeid'] = array();
$arr = explode(',', $row[1]);
foreach ($arr as $v) {
$v = trim($v);
if ($v == '') {
continue;
}
if (isset($grade_map[$v])) {
$row['ctg_gradeid'][] = $grade_map[$v];
} else {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"里有不正确的选项';
break;
}
}
if (isset($data['error'])) {
break;
}
if (empty($row['ctg_gradeid'])) {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"不能为空';
break;
}
$row['ctg_gradeid'] = array_unique($row['ctg_gradeid']);
// 学科
if ($row[2] == '') {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"不能为空';
break;
}
$row[2] = str_replace(array(',', ' ', ' ', '、', "\r\n", "\r", "\n"), ',', $row[2]);
$row['cts_subjectid'] = array();
$arr = explode(',', $row[2]);
foreach ($arr as $v) {
$v = trim($v);
if ($v == '') {
continue;
}
if (isset($subject_map[$v])) {
$row['cts_subjectid'][] = $subject_map[$v];
} else {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"里有不正确的选项空';
break;
}
}
if (isset($data['error'])) {
break;
}
if (empty($row['cts_subjectid'])) {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"不能为空';
break;
}
$row['cts_subjectid'] = array_unique($row['cts_subjectid']);
// 简介
if ($row[3] == '') {
$row[3] = NULL;
}
$ct_list[] = array('index' => $k + 2, 'ct_name' => $row[0], 'ct_memo' => $row[3], 'ctg_gradeid' => $row['ctg_gradeid'], 'cts_subjectid' => $row['cts_subjectid']);
//.........这里部分代码省略.........