本文整理汇总了PHP中PHPExcel_Reader_Excel5::listWorksheetNames方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Reader_Excel5::listWorksheetNames方法的具体用法?PHP PHPExcel_Reader_Excel5::listWorksheetNames怎么用?PHP PHPExcel_Reader_Excel5::listWorksheetNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Reader_Excel5
的用法示例。
在下文中一共展示了PHPExcel_Reader_Excel5::listWorksheetNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: excel
function excel($postdata)
{
require_once 'Excel_reader.php';
require_once 'Classes/PHPExcel.php';
$tmp = $postdata;
$save_path = "./";
//暂时上传的文件路径
$file_name = $save_path . date('Ymdhis') . ".xls";
//上传后的文件保存路径和名称
if (copy($tmp, $file_name)) {
}
$PHPExcel = new PHPExcel();
$PHPReader = new PHPExcel_Reader_Excel2007();
//为了可以读取所有版本Excel文件
if (!$PHPReader->canRead($file_name)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($file_name)) {
echo '未发现Excel文件!';
return;
}
}
//不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
$sheetNames = $PHPReader->listWorksheetNames($file_name);
//读取Excel文件
$PHPExcel = $PHPReader->load($file_name);
//获取工作表的数目
$sheetCount = $PHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; $i++) {
//选择第一个工作表
$currentSheet = $PHPExcel->getSheet($i);
//取得一共有多少列
$allColumn = $currentSheet->getHighestColumn();
//取得一共有多少行
$allRow = $currentSheet->getHighestRow();
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$address = $currentColumn . $currentRow;
$data[$i][$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
//echo ."\t";
}
}
//$data[$i]=$currentSheet;
}
unlink($file_name);
//删除上传的文件
return $data;
}
示例2: index
public function index()
{
// $xq_list = $this->manage_model->get_all_xiaoqu_list();
// foreach ($xq_list as $xq) {
// $name = str_replace("•","",$xq['name']);
// //echo $xq['id'] . ": " . $this->encode($name) . '<br>';
// $xq['jianpin'] = $this->encode($name);
// $this->manage_model->update_xiaoqu_jianpin($xq);
// }
// die('DONE');
require_once APPPATH . 'libraries/PHPExcel/PHPExcel.php';
$PHPExcel = new \PHPExcel();
$PHPReader = new \PHPExcel_Reader_Excel2007();
$file = 'E:/broker.xlsx';
//为了可以读取所有版本Excel文件
if (!$PHPReader->canRead($file)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($file)) {
echo '未发现Excel文件!';
return;
}
}
//不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
$sheetNames = $PHPReader->listWorksheetNames($file);
//读取Excel文件
$PHPExcel = $PHPReader->load($file);
//获取工作表的数目
$sheetCount = $PHPExcel->getSheetCount();
//选择第一个工作表
$currentSheet = $PHPExcel->getSheet(0);
//取得一共有多少列
$allColumn = $currentSheet->getHighestColumn();
//取得一共有多少行
$allRow = $currentSheet->getHighestRow();
//循环读取数据,默认编码是utf8,这里转换成gbk输出
$data = array();
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
$name = trim($currentSheet->getCell("A" . $currentRow)->getValue());
$tel = trim($currentSheet->getCell("B" . $currentRow)->getValue());
$data[] = array('username' => $tel, 'passwd' => sha1('888888'), 'tel' => $tel, 'company_name' => "顺达地产", 'rel_name' => $name, 'region_id' => 6, 'admin_group' => 2);
}
$this->manage_model->add_broker_batch($data);
}
示例3: _phydata
private function _phydata($fileinfo, $ac = 'phydata')
{
//import('Think.Cache');
//$Cache = \Cache::getInstance();
//查看是否截止上报
$school_year_info = D('SchoolYear')->get_info($this->school_year);
if (empty($school_year_info) || $school_year_info['state'] == 207020) {
$this->ajaxReturn(array('errno' => 101, 'errtitle' => '您选择的学年' . $this->school_year . '未开始,无法录入'));
}
//审核状态
$userinfo = session('userinfo');
$dictList = session('dictList');
//非补录数据需要验证上报状态
if ($ac != 'historyPhydata') {
if (!empty($school_year_info['not_upload_time']) && time() > strtotime($school_year_info['not_upload_time'])) {
$this->ajaxReturn(array('errno' => 102, 'errtitle' => '数据上报截止时间为' . $school_year_info['not_upload_time']));
}
//朝阳区功能
//if($userinfo['org_id'] == 110105){
// $this->ajaxReturn(array('errno'=>109,'errtitle'=>'功能暂未开放!'));
//}
if ($userinfo['org_id'] != 110105 && $userinfo['user_kind'] != '109010') {
$s_status = D('SchoolStatus')->get_status_info_one($this->school_year, $this->school_code);
if ($s_status['s_status'] == 206020 || $s_status['s_status'] == 206030) {
$this->ajaxReturn(array('errno' => 109, 'errtitle' => '您当前上报状态为' . $dictList['206'][$s_status['s_status']]['dict_name'] . ',如需重新上报或修改请等待区县撤销!'));
}
}
}
//读取excel文件内容
$fPath = '/Upload/' . $fileinfo['info']['savepath'] . $fileinfo['info']['savename'];
//文件大小限制
$filesize = filesize($_SERVER['DOCUMENT_ROOT'] . $fPath);
if ($filesize > 2097152) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $fPath);
$this->ajaxReturn(array('errno' => 111, 'errtitle' => '请不要上传超过2M的文件!'));
}
import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.IOFactory");
$reader = \PHPExcel_IOFactory::createReader('Excel2007');
$PHPExcel = \PHPExcel_IOFactory::load($_SERVER['DOCUMENT_ROOT'] . $fPath);
$reader->setReadDataOnly(true);
$PHPReader = new \PHPExcel_Reader_Excel2007();
//为了可以读取所有版本Excel文件
if (!$PHPReader->canRead($_SERVER['DOCUMENT_ROOT'] . $fPath)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($_SERVER['DOCUMENT_ROOT'] . $fPath)) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $fPath);
$this->ajaxReturn(array('errno' => 104, 'errtitle' => '未发现excel文件!'));
}
}
////不需要读取整个Excel文件而获取所有工作表数组的函数
$sheetNames = $PHPReader->listWorksheetNames($_SERVER['DOCUMENT_ROOT'] . $fPath);
if ($userinfo['org_id'] != 110105) {
$sheetNames = array($this->school_code);
} else {
if (empty($sheetNames)) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $fPath);
$this->ajaxReturn(array('errno' => 1115, 'errtitle' => 'excel内容为空!'));
}
}
/*表头*/
$key_base = array('grade_num', 'class_num', 'class_name', 'country_education_id', 'folk_code', 'name', 'sex', 'birthday', 'address');
$titContent = array('body_height' => '身高', 'body_weight' => '体重', 'vital_capacity' => '肺活量', 'wsm' => '50米跑', 'ldty' => '立定跳远', 'zwtqq' => '坐位体前屈', 'bbm_nv' => '800米跑(女)', 'yqm_nan' => '1000米跑(男)', 'ywqz_nv' => '一分钟仰卧起坐(女)', 'ytxs_nan' => '引体向上(男)', 'wsmwfp' => '50米×8往返跑', 'yfzts' => '一分钟跳绳', 'ywqz_ytxs' => '一分钟仰卧起坐');
$gradeItem = C('GRADE_ITEM_FIELD');
//判断验证学籍号还是教育ID号
if ($ac == 'phydata2') {
$field = 'education_id';
$fieldTitle = '教育ID号';
} else {
$field = 'country_education_id';
$fieldTitle = '全国学籍号';
}
/*表头end*/
//循环sheet
//记录错误内容
$errorLog = '';
//启动事务
M()->startTrans();
foreach ($sheetNames as $sk => $sname) {
$this->school_code = $sname;
$this->school_id = D('School')->get_list_by_schoolcode_year($this->school_code, $this->school_year, 'one');
if (empty($this->school_id)) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $fPath);
$this->ajaxReturn(array('errno' => 1116, 'errtitle' => 'sheet名称为' . $sname . '的学校代码错误,找不到该学校'));
break;
}
$this->school_id = $this->school_id['school_id'];
$schoolids[] = $this->school_id;
/*读取每一页内容*/
$sheet = $PHPExcel->getSheet($sk);
//sheet1
$highestRow = $sheet->getHighestRow();
//总行数
$highestColumn = $sheet->getHighestColumn();
//总列数,字母表示
//判断是否空文件
if ($highestRow <= 1) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $fPath);
$this->ajaxReturn(array('errno' => 103, 'errtitle' => '您上传的文件没有内容!'));
}
//.........这里部分代码省略.........