Excel 表格数据存储mysql数据库|三级分类
2016-12-19 10:10
399 查看
背景:近期在做商品的三级分类时发现,需要将Excel表格中的数据导入到数据库中进行后期的数据操作,通过度娘的介绍,以及针对此项目功能的设计要求,参考如下:
1.在自己的项目中,导入Excel继承类
网上有很多可使用的代码包,此处以ThinkPHP框架为参考,保证路径的正确性...
2.补充,上一步中所调用的公共函数format_excel2array()
3.运行函数
可以在数据库对应的third_category表中,查看得到的结果
4.三级分类前端设计效果。
5.三级分类前端代码/js
附录JS代码参考:
6.附录代码 >>>
1.在自己的项目中,导入Excel继承类
网上有很多可使用的代码包,此处以ThinkPHP框架为参考,保证路径的正确性...
2.补充,上一步中所调用的公共函数format_excel2array()
/** * excel表数据转化为数组 * @param string $filePath * @param int $sheet * @return array|void */ function format_excel2array($filePath='',$sheet=0){ if(empty($filePath) or !file_exists($filePath)){die('file not exists');} $PHPReader = new PHPExcel_Reader_Excel2007(); //建立reader对象 if(!$PHPReader->canRead($filePath)){ $PHPReader = new PHPExcel_Reader_Excel5(); if(!$PHPReader->canRead($filePath)){ echo 'no Excel'; return ; } } $PHPExcel = $PHPReader->load($filePath); //建立excel对象 $currentSheet = $PHPExcel->getSheet($sheet); //**读取excel文件中的指定工作表*/ $allColumn = $currentSheet->getHighestColumn(); //**取得最大的列号*/ $allRow = $currentSheet->getHighestRow(); //**取得一共有多少行*/ $data = array(); for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){ //循环读取每个单元格的内容。注意行从1开始,列从A开始 for($colIndex='A';$colIndex<=$allColumn;$colIndex++){ $addr = $colIndex.$rowIndex; $cell = $currentSheet->getCell($addr)->getValue(); if($cell instanceof PHPExcel_RichText){ //富文本转换字符串 $cell = $cell->__toString(); } $data[$rowIndex][$colIndex] = $cell; } } return $data; }
3.运行函数
可以在数据库对应的third_category表中,查看得到的结果
4.三级分类前端设计效果。
5.三级分类前端代码/js
附录JS代码参考:
6.附录代码 >>>
相关文章推荐
- MySQL mysqldump 导入/导出 结构&数据&存储过程&函数&事件&触发器
- Mysql 常用SQL语句集锦
- mysql主从同步问题解决汇总
- MySql事务机制
- MySQL定时事件
- Mysql 常用SQL语句集锦
- MySQL系列—DATE_SUB 使用方法结合查询一天内,一周内,一月内的信息实例讲解
- MySQL之alter语句用法总结
- MYSQL常用命令
- MySQL创建表
- [PowerDesign]将数据库从SQL Server数据库转换为MySQL
- Mysql远程登录配置
- MySQL中捕获低效SQL语句的配置以及检测SQL语句效率的方法
- MySQL中的锁(表锁、行锁)
- Mysql 服务无法启动 服务没有报告任何错误
- mysql-5.7.17-winx64免安装版环境配置 问题小记
- mysql-5.7.17-winx64免安装版环境配置 问题小记
- 附录B 安装MySql数据库
- MySQL查询缓存详解
- MySQL 使用 SSL 连接配置详解