CI框架(CodeIgniter)实现的导入、导出数据操作示例
发布时间:2021-05-28 13:06:58 所属栏目:编程 来源:网络整理
导读:本篇章节讲授CI框架(CodeIgniter)实现的导入、导出数据操纵。供各人参考研究详细如下: 在libraies中引用PHPExcel这个类(phpexcel.php) 'name','C
本篇章节讲授CI框架(CodeIgniter)实现的导入、导出数据操纵。分享给各人供各人参考,详细如下: 在libraies中引用PHPExcel这个类(phpexcel.php) 'name','C'=>'pwd','D'=>'money1','E'=>'salt');
$data=array('B'=>'name','C'=>'pid');
$tablename='city2';//表名字
$this->excel_fileput($filePath,$data,$tablename);
}
load->library("phpexcel");//ci框架中引入excel类
$PHPExcel = new PHPExcel();
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
// 加载excel文件
$PHPExcel = $PHPReader->load($filePath);
// 读取excel文件中的第一个事变表
$currentSheet = $PHPExcel->getSheet(0);
// 取得最大的列号
$allColumn = $currentSheet->getHighestColumn();
// 取得一共有几多行
$allRow = $currentSheet->getHighestRow();
// 从第二行开始输出,由于excel表中第一举动列名
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
/**从第A列开始输出*/
//echo $allColumn;
for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){
$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue();
//print_r($val);
//die;
if($currentColumn == 'A')
{
//echo $val."t";
}else if($currentColumn <= $allColumn){
$data1[$currentColumn]=$val;
}
}
foreach($data as $key=>$val){
$data2[$val]=$data1[$key];
}
$this->db->insert($tablename,$data2);
//print_r($data2);
//echo "";
}
//echo "n";
echo "导入乐成";
}
导出数据: db->get("city")->result_array();
$str="idt"."namet"."pidn";
foreach($array as $val){
$str.=$val['id']."t".$val['name']."t".$val['pid']."n";
}
echo $str;
}
更多关于CodeIgniter相干内容感乐趣的读者可查察本站专题:《》、《》、《》、《》、《》、《》、《》、《》及《》 但愿本文所述对各人基于CodeIgniter框架的PHP措施计划有所辅佐。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |