跳至
[1]
[全屏预览]
<?php header("Content-Type:text/html;charset=utf-8"); $dir = $_POST['exceldir']; /** PHPExcel_IOFactory */ require_once 'PHPExcel.php'; if (!file_exists("$dir")) { exit("not found mb.xlsx.\n"); } $reader = PHPExcel_IOFactory::createReader('Excel2007'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load("$dir"); // 载入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; } //释放工作表对象 unset($sheet); //释放Excel文件对象 unset($PHPExcel); //返回数据 echo "导入成功!"; //删除文件 unlink($dir); ?>
Statement
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks agoByDDD
R.E.P.O. Save File Location: Where Is It & How to Protect It?
3 weeks agoByDDD

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
