Home php教程 php手册 php利用ExcelFileParser把excel导入数据库

php利用ExcelFileParser把excel导入数据库

May 26, 2016 pm 03:21 PM
excel import

这是一款实用的php教程利用excelfileparser把excel导入数据库教程,代码如下:

<!doctype html>  
<html>  
<head>  
<meta http-equiv="content-type" content="text/html; charset=utf-8" />  
<title>excel数据获取演示</title>  
<meta name="keywords" content="todo" />  
<meta name="description" content="todo"/>  
</head>  
<body>  
<div>  
<div>excel数据获取演示</div>  
<div>  
<form method="post" action="/index/parse" enctype="multipart/form-data">  
<input type="file" name="excel" value="" />  
<input type="submit" name="submit" value="提交" />  
</form>  
</div>  
</div>  
</body>  
</html>
Copy after login

parese.php文件,代码如下:

<?php
/**  
 * copyright (c) 2009,
 * all rights reserved.
 * 文件名:
 * 摘 要:
 *
 * @author 星期八 [url=mailto:ixqbar@hotmail.com]ixqbar@hotmail.com[/url]
 * @version
 */
public function parse()  
{  
/**  
* $_files数组说明  
* array(n) {  
* ["表单文件框名称"] => array(5) {  
* ["name"] => 提交文件名称  
* ["type"] => 提交文件类型 excel为"application/vnd.ms-excel"  
* ["tmp_name"] => 临时文件名称  
* ["error"] => 错误(0成功1文件太大超过upload_max_filesize2文件太大超过max_file3上传不完整4没有上传文件)  
* ["size"] => 文件大小(单位:kb)  
* }  
* }  
*/  
$return=array(0,&#39;&#39;);  
/**  
* 判断是否提交  
* is_uploaded_file(文件名称)用于确定指定的文件是否使用post方法上传,防止非法提交,通常和move_upload_file一起使用保存上传文件到指定的路径  
*/  
if(!isset($_files) || !is_uploaded_file($_files[&#39;excel&#39;][&#39;tmp_name&#39;]))  
{  
    $return=array(1,&#39;提交不合法&#39;);  
}  
//处理  
if(0 == $return[0])  
{  
    import(&#39;@.util.excelparser&#39;);  
    $excel=new excelparser($_files[&#39;excel&#39;][&#39;tmp_name&#39;]);  
    $return=$excel->main();  
}
//输出处理  
print_r($return);  
?>
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

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel development: How to use Laravel Excel to implement Excel import and export? Laravel development: How to use Laravel Excel to implement Excel import and export? Jun 13, 2023 pm 02:55 PM

Laravel development: How to use LaravelExcel to implement Excel import and export? During development, Excel tables are often used for data processing, such as data import and export. LaravelExcel is a simple and powerful Laravel extension that allows us to easily process Excel files, including reading, writing, and exporting operations of Excel files. In this article we will introduce how to use LaravelExcel

How to use ThinkPHP6 to import and export Excel? How to use ThinkPHP6 to import and export Excel? Jun 12, 2023 am 09:23 AM

With the development of the Internet, there are increasing needs for data import and export, especially in enterprises. As a very popular office software, Excel is also widely used for data storage and processing. Therefore, how to use ThinkPHP6 to import and export Excel has become a very important issue. This article will introduce the steps for Excel import and export using ThinkPHP6. 1. Excel export ThinkPHP6 provides a very convenient Excel export tool class

Summary of common problems when importing Excel data into Mysql: How to solve the garbled problem encountered when importing data? Summary of common problems when importing Excel data into Mysql: How to solve the garbled problem encountered when importing data? Sep 08, 2023 pm 05:58 PM

Summary of common problems when importing Excel data into Mysql: How to solve the garbled problem encountered when importing data? Importing Excel data into Mysql database is a common task in daily work. However, sometimes during the import process, garbled characters may be encountered, resulting in incorrect data display. This article will summarize common garbled code problems and provide solutions to help readers solve the garbled code problem when importing data. Problem: After importing data, Chinese characters become garbled and appear as a string of garbled characters. Solution: Generally speaking, this is due to the character

How to use Hyperf framework for Excel import How to use Hyperf framework for Excel import Oct 21, 2023 am 08:42 AM

How to use the Hyperf framework to import Excel requires specific code examples. Introduction: With the development of informatization, spreadsheets play an important role in our daily work. During the development process, we often encounter situations where we need to import data from Excel into the system. This article will introduce how to use the Hyperf framework for Excel import and provide specific code examples. 1. Install the necessary plug-ins. Before using the Hyperf framework to import Excel, we need to install two plug-ins.

How to import and export Excel in ThinkPHP6? How to import and export Excel in ThinkPHP6? Jun 12, 2023 am 11:01 AM

With the increasing popularity of Internet applications and the growing demand for interaction between various types of data and data transfer, file format conversion, import and export have become one of the common needs. In web applications, importing and exporting Excel files are common ways of data exchange in daily work. This article will introduce how to implement Excel import and export functions in the ThinkPHP6 framework. 1. Introduction to ThinkPHP6 framework ThinkPHP6 is a free, open source, fast and simple object-oriented lightweight framework.

Summary of frequently asked questions about importing Excel data into Mysql: How to solve data verification problems encountered during the import process? Summary of frequently asked questions about importing Excel data into Mysql: How to solve data verification problems encountered during the import process? Sep 10, 2023 pm 01:46 PM

Summary of frequently asked questions about importing Excel data into Mysql: How to solve data verification problems encountered during the import process? Importing Excel data into a MySQL database is an operation we often need to perform in data processing work. However, we often encounter some data verification problems during this process, causing the import to fail or the imported data not to meet our expectations. The following will introduce some common problems and solutions to help you avoid these troubles in actual operations. Question 1: When importing Excel data, Mysq

Summary of frequently asked questions about importing Excel data into Mysql: How to solve primary key conflicts encountered during import? Summary of frequently asked questions about importing Excel data into Mysql: How to solve primary key conflicts encountered during import? Sep 12, 2023 pm 02:30 PM

Summary of frequently asked questions about importing Excel data into Mysql: How to solve primary key conflicts encountered during import? Importing data is one of the common tasks in data management work, especially when you need to import a large amount of data from an Excel table to a Mysql database, you may encounter a variety of problems. One of the common problems is primary key conflict. Primary key conflict problems generally occur when importing data. The main reason is that the data in the Excel table conflicts with the primary key of the existing data in the database. This may be because Excel

How to use ThinkPHP6 to implement Excel import and export How to use ThinkPHP6 to implement Excel import and export Jun 21, 2023 pm 06:01 PM

With the rapid development of the Internet, Excel has become one of the important tools in daily office work for companies and individuals. Therefore, Excel's ability to import and export has become a necessary part of many applications. How to use ThinkPHP6 to implement Excel import and export? Below, this article will introduce it to you in detail. 1. ThinkPHP6 system environment verification To use ThinkPHP6 to implement Excel import and export, you first need to meet the system environment requirements. In ThinkPHP6, you can use c

See all articles