How to import PHPExcel files into Thinkphp3.2.3
This article will share with you how to import PHPExcel files into Thinkphp3.2.3. It has certain reference value. Friends in need can refer to it
1. First of all, First download the PHPExcel plug-in:
ThinkPHP version: 3.2.3
PHPExcel version: 1.8
##PHPExcel official Download address: https://github.com/PHPOffice/PHPExcel
2. After decompression, it is as follows:
As long as the Classes folder is used, the others are of no use. Change the name of the classes folder to PHPExcel (name it whatever you want)
3. Copy the PHPExcel file to Thinkphp, the location is as follows
4. Everything is ready, open as we journey.
##Front-end code: <form action="{:U('Index/upload')}" method="post" enctype="multipart/form-data">
<ul>
<li><input type="file" name="files" /></li>
<li><input type="submit" value="上传" /></li>
</ul>
</form>
Backend code(upload method in IndexController.class.php): public function upload(){
if(isset($_FILES["files"]) && ($_FILES["files"]["error"] == 0)){
$result = importExecl($_FILES["files"]["tmp_name"]);
echo '<pre />';
print_r($result);
die;
}
}
Among them
Written in a public method, the location is as follows
:function importExecl($file='', $sheet=0){
$file = iconv("utf-8", "gb2312", $file); //转码
if(empty($file) OR !file_exists($file)) {
die('file not exists!');
}
vendor("PHPExcel.PHPExcel"); // 引入我们自己导入的文件
$objRead = new PHPExcel_Reader_Excel2007(); //建立reader对象
if(!$objRead->canRead($file)){
$objRead = new PHPExcel_Reader_Excel5();
if(!$objRead->canRead($file)){
die('No Excel!');
}
}
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI',
'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU',
'AV', 'AW', 'AX', 'AY', 'AZ');
$obj = $objRead->load($file); //建立excel对象
$currSheet = $obj->getSheet($sheet); //获取指定的sheet表
$columnH = $currSheet->getHighestColumn(); //取得最大的列号
$columnCnt = array_search($columnH, $cellName);
$rowCnt = $currSheet->getHighestRow(); //获取总行数
$data = array();
for($_row=1; $_row<=$rowCnt; $_row++){ //读取内容
for($_column=0; $_column<=$columnCnt; $_column++){
$cellId = $cellName[$_column].$_row;
$cellValue = $currSheet->getCell($cellId)->getValue();
//$cellValue = $currSheet->getCell($cellId)->getCalculatedValue(); #获取公式计算的值
if($cellValue instanceof PHPExcel_RichText){ //富文本转换字符串
$cellValue = $cellValue->__toString();
}
$data[$_row][$cellName[$_column]] = $cellValue;
}
}
return $data;
}
##6. Finally, the code is relatively simple to write. You can verify the type and size yourself, so I won’t write them here. I personally tested the above code and found no problem.
The above is the detailed content of How to import PHPExcel files into Thinkphp3.2.3. For more information, please follow other related articles on the PHP Chinese website!

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

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



When we use this platform to listen to songs, most of them should have some songs that you want to listen to. Of course, some things may not be listened to because there is no copyright. Of course, we can also directly use some songs imported locally. Go up there so you can listen. We can download some songs and directly convert them into mp3 formats, so that they can be scanned on the mobile phone for import and other situations. However, for most users, they don’t know much about importing local song content, so in order to solve these problems well, today the editor will also explain it to you. The content method allows you to make better choices without asking. If you are interested,

How to use Vue to implement Excel import function Vue.js is a popular JavaScript framework for building user interfaces. It provides many convenient features and easy-to-use API, allowing us to quickly build feature-rich applications. In this article, we will introduce how to use Vue.js to implement Excel import function. First, we need to install a library called "xlsx", which is a JavaScript library that parses and extracts Excel file data.

OpenIV is a very convenient tool that can be used to import OIV files in GTA games. OIV files are a specific file format used to package mod or modification files into an easy-to-install format. This article will introduce how to use OpenIV to import OIV files. First, make sure you have the OpenIV software installed. If not, you can download it from the official website and follow the instructions to install it. Next, download the required OIV file from a trusted source. You can find various GTA modding communities or M

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

Complete Guide: How to Process Excel Files Using PHP Extension PHPExcel Introduction: Excel files are often used as a common format for data storage and exchange when processing large amounts of data and statistical analysis. Using the PHP extension PHPExcel, we can easily read, write and modify Excel files to effectively process Excel data. This article will introduce how to use the PHP extension PHPExcel to process Excel files and provide code examples. 1. Install PHPExc

With the advent of the digital age, data has become the most important part of our daily lives and work, and Excel files have become one of the important tools for data processing. I believe that many PHP developers will often encounter the use of Excel files for data processing and operations at work. This article will introduce you to the methods and precautions for using the PHPExcel library to process Excel files. What is PHPExcel? PHPExcel is a PHP class

Do you know how to import external playlists on Soda Music App? Many users of the latest version of Soda Music App, when importing some playlists, do not like to import their own songs into the playlist, but this is limited. You can manage the classification of some of your songs very well when you listen to it, so friends who have ideas must give it a try and find out more. I believe you will like it, and you can have any ideas. Step-by-step tutorial for importing external playlists from Soda Music: 1. On the Soda Music app page, click and select the lower right corner to create a playlist. 2. Create a page, enter the playlist name, and click Save. 3. On the My Playlist page, select Add Songs. 4. Search, select your favorite songs, and add them to the playlist

Everyone has several different music software installed on their mobile phone, and everyone likes to save their favorite songs in their favorites. Today we will talk about QQ Music, which not only supports one-click import of external playlists, but is also very convenient to operate. Next, the editor of this site will lead you to learn in detail how to import external playlists from QQ Music. If you are in need, please follow the editor and take a look! Introducing the detailed operation method of how to import external playlists in QQ Music. First, open QQ Music and enter the homepage. Then, click "My" below to enter my interface. Scroll down and you will see an option to "Import external playlist". Clicking it will jump to another page. On that page, you need to copy the link to the external playlist and
