The most basic usage of importing thinkphp3.2 and phpexcel
Start with the most basic code. Once you understand this, the rest will be very simple$file_name= './Upload/excel/123456.xls';<br>
import("Org.Util.PHPExcel");<br>
import("Org.Util.PHPExcel.IOFactory");<br>
$objReader = PHPExcel_IOFactory::createReader('Excel5');<br>
$objPHPExcel = $objReader->load($file_name,$encode='utf-8');<br>
$sheet = $objPHPExcel->getSheet(0);<br>
$highestRow = $sheet->getHighestRow(); // 取得总行数<br>
$highestColumn = $sheet->getHighestColumn(); // 取得总列数<br>
<br>
$s = $objPHPExcel->getActiveSheet()->getCell("A2")->getValue();
Table content:
I’ll give you a little more difficulty and let’s talk about the idea first.
1. Upload the excel file and get its address
2. Write a function to process exl, that’s it
Example code demonstration: public function upload(){<br>
$files = $_FILES['exl'];<br>
// exl format, otherwise re-upload <br>
If($files['type'] !='application/vnd.ms-excel'){<br>
$this->error('Not an Excel file, please re-upload');
}<br>
// Upload<br>
$upload = new ThinkUpload(); // Instantiate upload class<br>
$upload->maxSize
$upload->exts
$ Upload-& gt; rootpath = './upload/'; // Set the attachment to upload the root directory <br>
$upload->savePath = 'excel/'; // Set attachment upload (sub) directory <br>
//$upload->subName = array('date', 'Ym');<br>
$upload->subName
// Upload files <br>
$info = $upload->upload();<br>
<br>
$file_name = $upload->rootPath.$info['exl']['savepath'].$info['exl']['savename'];<br>
$exl = $this->import_exl($file_name);<br>
//Remove the first row in the exl table<br>
unset($exl[0]);<br>
// Clean up empty arrays<br>
foreach($exl as $k=>$v){<br>
If(empty($v)){<br>
Unset ($ exl [$ k]); <br>
};<br>
//Reorder<br> sort($exl);<br>
$count = count($exl);<br>
// After the test form is imported successfully, whether there is data generating <br>
If($count
$this->error('No valid data detected');
}<br>
//Start combining data<br>
foreach($exl as $k=>$v){<br>
$goods[$k]['goods_sn'] = $v;<br>
// Query database
$where['goods_sn'] = array('like','%'.$v.'%');<br>
$res = M('goods')->where($where)->find();<br>
$goods[$k]['goods_name'] = $res['goods_name'];<br>
$goods[$k]['goods_thumb'] = $res['goods_thumb'];<br>
if($res){<br>
’ s being being matched successfully' s
$goods[$k]['is_match']
$f = 1;<br>
}else{<br>
-- // Matching failed <br>
$goods[$k]['is_match']
}<br>
}<br>
// Instantiation data<br>
$this->assign('goods',$goods);<br>
//print_r($f);<br>
//Statistical results<br>
$total['count'] = $count;<br>
$total['success'] = $f;<br>
$total['error'] = $w;<br>
$this->assign('total',$total);<br>
//Delete Excel file<br>
unlink($file_name);<br>
$this->display('info');<br>
}<br>
/* Process uploaded exl data<br>
* $file_name File path<br>
*/<br>
Public function import_exl($file_name){<br>
//$file_name= './Upload/excel/123456.xls';<br>
import("Org.Util.PHPExcel"); .Import("Org.Util.PHPExcel.IOFactory");<br>
$objReader = PHPExcel_IOFactory::createReader('Excel5');<br>
$objPHPExcel = $objReader->load($file_name,$encode='utf-8');<br>
$sheet = $objPHPExcel->getSheet(0);<br>
$highestRow = $sheet->getHighestRow(); // Get the total number of rows<br>
$highestColumn = $sheet->getHighestColumn(); // Get the total number of columns <br>
for($i=1;$i
}<br>
Return $data;
}<br>Perfect case of generating pictures with thinkphp3.2 and phpexcel<br>
http://www.thinkphp.cn/code/2112.html <br> Yunqi Conference Beijing Station: It is rare for Alibaba technical experts to appear on the scene. More than 100 people came this time? !

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

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