'name','C'=>'pwd','D'=>'money1','E'=>'salt'); $data=array('B'=>'name','C'=>'pid'); $tablename='city2';//表名字 $this->excel_fileput($filePath,$data,$tablename); }
privatefunctionexcel_fileput($filePath,$data,$tablename){
$this->load->library("phpexcel");//ci框架中引入excel类
$PHPExcel=newPHPExcel();
$PHPReader=newPHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader=newPHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo'noExcel';
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";
}elseif($currentColumn<=$allColumn){
$data1[$currentColumn]=$val;
}
}
foreach($dataas$key=>$val){
$data2[$val]=$data1[$key];
}
$this->db->insert($tablename,$data2);
//print_r($data2);
//echo"
"; } //echo"\n"; echo"导入成功"; }

导出数据:

publicfunctionexcel_out(){
header("Content-type:text/html");
header("Content-Disposition:attachment;filename=123.xls");
$array=$this->db->get("city")->result_array();
$str="id\t"."name\t"."pid\n";
foreach($arrayas$val){
$str.=$val['id']."\t".$val['name']."\t".$val['pid']."\n";
}
echo$str;
}

更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《ZendFrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

热门推荐

1 给升迁同事祝福语简短
2 绝美老师花束祝福语简短
3 结婚请柬祝福语简短搞笑
4 部队牛年祝福语简短的
5 音乐生祝福语大全简短
6 用名字做祝福语简短
7 同学妈妈手术祝福语简短
8 生日毕业祝福语简短英文
9 爸妈对宝宝祝福语简短
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短