php通过PHPExcel读取excel中的内容到mysql数据库
跳至
[1]
[全屏预览]
<?php header("Content-Type:text/html;charset=utf-8"); /** PHPExcel_IOFactory */ require_once 'PHPExcel.php'; if (!file_exists("mb.xlsx")) { exit("not found mb.xlsx.\n"); } $reader = PHPExcel_IOFactory::createReader('Excel2007'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load("mb.xlsx"); // 载入excel文件 $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表 $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumm = $sheet->getHighestColumn(); // 取得总列数 //1.导入配置文件 require("conf/dbconfig.php"); //2.连接MySQL、并选择数据库 $link = @mysql_connect(HOST, USER, PASS) or die("数据库连接失败!"); mysql_select_db(DBNAME, $link); //循环读取excel文件,读取一条,插入一条 for ($j = 2; $j <= $highestRow; $j++) { $name = $PHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();//获取A列的值 $telephone = $PHPExcel->getActiveSheet()->getCell("B" . $j)->getValue();//获取B列的值 $fenzu = $PHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();//获取C列的值 $school = $PHPExcel->getActiveSheet()->getCell("D" . $j)->getValue();//获取D列的值 $banji = $PHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();//获取E列的值 $sql = "INSERT INTO `drtable`(`id`, `name`, `telephone`, `fenzu`, `school`, `banji`) VALUES (null,'{$name}','{$telephone}','{$fenzu}','{$school}','{$banji}')"; mysql_query($sql, $link); echo $sql; } ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD
Nordhold: Fusion System, Explained
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1665
14


CakePHP Tutorial
1423
52


Laravel Tutorial
1321
25


PHP Tutorial
1269
29


C# Tutorial
1249
24

