PHP+PHPEXCELREADER+MYSQ实现EXCEL表批量导入MYSQL
来源:互联网 发布:软件质量管理体系流程 编辑:程序博客网 时间:2024/05/19 22:52
这个功能,主要是为了把大气监测数据批量导入MYSQL数据库而写的。其实,只要把insert.php文件中的数据库选项,就可以添加其他的数据了。这里提供的是一种原理。
up.php选择文件上传。PS:要实现此功能,还需要下载phpexcelreader源代码。GOOGLE一下,你懂的。
<script>function import_check(){<!--上传文件用的--> var f_content = form1.file.value; var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length) fileext=fileext.toLowerCase() if (fileext!='.xls') { alert("对不起,导入数据格式必须是xls格式文件哦,请您调整格式后重新上传,谢谢!"); return false; }}</script> <table width="98%" border="0" align="center" style="margin-top:20px; border:1px solid #9abcde;"> <form id="form1" name="form1" enctype="multipart/form-data" method="post" action="insert.php"> <tr > <td height="28" colspan="2" background="../skins/top_bg.gif"><label> <strong><a href="#">乡镇PM10数据导入,慎用</a></strong></label></td> </tr> <tr> <td width="18%" height="50"> 选择你要导入的数据表</td> <td width="82%"><label> <input name="file" type="file" id="file" size="50" /> </label> <label> <input name="button" type="submit" class="nnt_submit" id="button" value="导入数据" onclick="import_check();"/> </label> </td> </tr> <tr> <td colspan="2" bgcolor="#DDF0FF"> [<span class="STYLE1">注</span>]数据导入格式说明:</td> </tr> <tr> <td colspan="2"> 1、其它.导入数据表文件必须是<strong>execel</strong>文件格式{.<span class="STYLE2">xls</span>}为扩展名.</td> </tr> <tr> <td colspan="2"> 2、execel文件导入数据顺序必须严格按照规定顺序。</td> </tr> <tr> <td colspan="2"> </td> </tr></form> </table>
insert.php往数据库写入数据
<?php //往数据库中写入数据error_reporting(E_ALL ^ E_NOTICE);if($_POST){$Import_TmpFile = $_FILES['file']['tmp_name'];require_once '../configywcl.php'; require_once 'Excel/reader.php';$data = new Spreadsheet_Excel_Reader();$data->setOutputEncoding('UTF-8');$data->read($Import_TmpFile);$array =array(); for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $array[$i][$j] = $data->sheets[0]['cells'][$i][$j]; }}sava_data($array);}function sava_data($array){ $count =0; $total =0; foreach( $array as $tmp){ //echo $tmp[1];//$tmp[1]=date('Y-m-d',$tmp[1]); $sql = "Insert into xzdq (rq,nian,yue,ri,xl,gc,cy,yc,dd,cg,sl,hch,llh,qlh,lx,zkd,cgou,dsw,zf,sd,pw,sjy,das,xyl,fzz,nj,hb,fqgc,gd,df,rqzx,bz) value('$tmp[1]','$tmp[2]','$tmp[3]','$tmp[4]','$tmp[5]','$tmp[6]','$tmp[7]','$tmp[8]','$tmp[9]','$tmp[10]','$tmp[11]','$tmp[12]','$tmp[13]','$tmp[14]','$tmp[15]','$tmp[16]','$tmp[17]','$tmp[18]','$tmp[19]','$tmp[20]','$tmp[21]','$tmp[22]','$tmp[23]','$tmp[24]', '$tmp[25]','$tmp[26]','$tmp[27]','$tmp[28]','$tmp[29]','$tmp[30]','$tmp[31]','$tmp[32]')";//echo $sql."<br>"; if( mysql_query($sql) ){ $count++; } $total++; } echo "<script>alert('共有".$total."条数据,导入".$count."条数据成功');</script>"; } function TtoD($text){ $jd1900 = GregorianToJD(1, 1, 1900)-2; $myJd = $text+$jd1900; $myDate = JDToGregorian($myJd); $myDate = explode('/',$myDate); $myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT); return $myDateStr; }?>
- PHP+PHPEXCELREADER+MYSQ实现EXCEL表批量导入MYSQL
- php导入excel文件功能开发 phpExcelReader
- phpExcelReader实现Excel解析
- phpExcelReader实现Excel解析
- 使用phpexcelreader插件 结合mysql 与 导入Excel文件(.xls)
- php 结合缓冲区读取excel数据并批量导入mysql
- PHP利用phpExcelReader读取Excel错误总结
- PHP 类实现Excel 导入Mysql
- PHP Excel 导入mysql
- 将Excel数据导入MySQ
- phpexcelreader导入表或导出表
- PHP实现Excel导入
- PHP实现Excel导入
- 批量将excel中的sheet表通过Navicat导入MySQL
- php的excel数据批量导入
- excel数据批量导入到Mysql数据库
- java批量导入excel到Mysql数据库
- 批量数据从excel导入到mysql
- Android笔记--NDK/JNI Log 输出
- php中 json 转 array
- POJ 1679 The Unique MST 次小生成树
- Oracle客户端软件-使用pl/sql配置登陆
- Qt学习笔记
- PHP+PHPEXCELREADER+MYSQ实现EXCEL表批量导入MYSQL
- 回头看,这可是我们的第N次会晤
- 面试问题背后的“猫腻”
- sql删除主附表事务回滚处理
- Prism应用开发(三)——基于模块的应用程序开发
- 使用tortoisegit访问github
- 减肥计划
- ]QT4 自定义槽和信号
- VC调用C#的COM组件(DLL)