


This article will introduce to you a PHPExcel code implementation for reading excel and importing it into the database. Friends who need to know more can refer to it. What we introduce here is to create a mysql connection after reading the table, and then save it to the mysql database.
PHPExcel is a very powerful MS Office Excel document generation class library. When you need to output data in a more complex format, PHPExcel is a good choice. However, its usage is relatively cumbersome
The code is as follows
|
Copy code | ||||
ini_set('memory_limit','-1');
require_once './PHPExcel.php';
require_once './PHPExcel/IOFactory.php';
require_once './PHPExcel/Reader/Excel5.php';
//Use pdo to connect to the database
$dsn = "mysql:host=localhost;dbname=alumni;";
$user = "root";
$password = "";
Try{
$dbh = new PDO($dsn,$user,$password);
$dbh->query('set names utf8;');
}catch(PDOException $e){
echo "Connection failed".$e->getMessage();
}
//pdo binding parameter operation
$stmt = $dbh->prepare("insert into alumni(gid,student_no,name) values (:gid,:student_no,:name) ");
$stmt->bindParam(":gid", $gid,PDO::PARAM_STR);
$stmt->bindParam(":student_no", $student_no,PDO::PARAM_STR);
$stmt->bindParam(":name", $name,PDO::PARAM_STR);
$objReader = new PHPExcel_Reader_Excel5(); //use excel2007
$objPHPExcel = $objReader->load('bks.xls'); //Specified file
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); // Get the total number of rows
$highestColumn = $sheet->getHighestColumn(); // Get the total number of columns
for($j=1;$j {
$student_no = $objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();//The first column of student number
$name = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();//Second column name
$gid = $objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();//The third column gid
}
//Insert the obtained excel content into the database
$stmt->execute();
?>
http: //www.bkjia.com/PHPjc/630718.html

如何使用pandas正确读取txt文件,需要具体代码示例Pandas是一个广泛使用的Python数据分析库,它可以用于处理各种各样的数据类型,包括CSV文件、Excel文件、SQL数据库等。同时,它也可以用于读取文本文件,例如txt文件。但是,在读取txt文件时,我们有时会遇到一些问题,例如编码问题、分隔符问题等。本文将介绍如何使用pandas正确读取txt

使用pandas读取txt文件的实用技巧,需要具体代码示例在数据分析和数据处理中,txt文件是一种常见的数据格式。使用pandas读取txt文件可以快速、方便地进行数据处理。本文将介绍几种实用的技巧,以帮助你更好的使用pandas读取txt文件,并配以具体的代码示例。读取带有分隔符的txt文件使用pandas读取带有分隔符的txt文件时,可以使用read_c

Java中使用OpenCSV读取和写入CSV文件的示例CSV(Comma-SeparatedValues)指的是以逗号分隔的数值,是一种常见的数据存储格式。在Java中,OpenCSV是一个常用的工具库,用于读取和写入CSV文件。本文将介绍如何使用OpenCSV来实现读取和写入CSV文件的示例。引入OpenCSV库首先,需要引入OpenCSV库到

Pandas读取网页数据的实用方法,需要具体代码示例在数据分析和处理过程中,我们经常需要从网页中获取数据。而Pandas作为一种强大的数据处理工具,提供了方便的方法来读取和处理网页数据。本文将介绍几种常用的Pandas读取网页数据的实用方法,并附上具体的代码示例。方法一:使用read_html()函数Pandas的read_html()函数可以直接从网页中读

快速入门:Pandas读取JSON文件的方法,需要具体代码示例引言:在数据分析和数据科学领域,Pandas是一个重要的Python库之一。它提供了丰富的功能和灵活的数据结构,能够方便地对各种数据进行处理和分析。在实际应用中,我们经常会遇到需要读取JSON文件的情况。本文将介绍如何使用Pandas来读取JSON文件,并附上具体的代码示例。一、Pandas的安装

PHP读取Excel文件方法及常见问题解答Excel是一种非常普遍的电子表格文件格式,很多业务和数据都存放在Excel文件中。在开发过程中,如果需要将Excel文件中的数据导入系统中,就需要使用PHP读取Excel文件。本文将介绍PHP读取Excel文件的方法及常见问题解答。一、PHP读取Excel文件方法1.使用PHPExcel类库PHPExcel是一个P

完全指南:如何使用PHP扩展PHPExcel处理Excel文件引言:在处理大量数据和统计分析时,Excel文件经常被用作数据存储和交换的一种常见格式。使用PHP扩展PHPExcel,我们可以轻松地读取、写入和修改Excel文件,从而有效地处理Excel数据。本文将介绍如何使用PHP扩展PHPExcel来处理Excel文件,并提供代码示例。一、安装PHPExc

随着数字化时代的到来,数据已经成为了我们日常生活和工作中最重要的一部分,而Excel文件则成为数据处理的重要工具之一。相信很多PHP开发者也会在工作中经常遇到使用Excel文件进行数据处理和操作的情况。本文将为大家介绍使用PHPExcel库来处理Excel文件的方法和注意事项。什么是PHPExcel?PHPExcel是一个PHP类


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

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

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