search
Homephp教程php手册Thinkphp使用PHPExcel实现导入Excel

Thinkphp使用PHPExcel实现导入Excel
  public function __construct() {<br>   <br>     /*导入phpExcel核心类 */<br>     require_once APP_PATH.'PHPExcel/PHPExcel.php'; <br>     require_once APP_PATH.'PHPExcel/PHPExcel/Writer/Excel5.php';     // 用于其他低版本xls <br>     require_once APP_PATH.'PHPExcel/PHPExcel/Writer/Excel2007.php'; // 用于 excel-2007 格式 <br>   }<br> <br> <br> //导入excel内容转换成数组 <br> public function import($filePath){<br>   $this->__construct();<br>   $PHPExcel = new PHPExcel(); <br> <br>   /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ <br>   $PHPReader = new PHPExcel_Reader_Excel2007(); <br>     if(!$PHPReader->canRead($filePath)){ <br>       $PHPReader = new PHPExcel_Reader_Excel5(); <br>       if(!$PHPReader->canRead($filePath)){ <br>         echo 'no Excel'; <br>         return; <br>       } <br>     } <br>   <br>   $PHPExcel = $PHPReader->load($filePath); <br>   $currentSheet = $PHPExcel->getSheet(0);  //读取excel文件中的第一个工作表<br>   $allColumn = $currentSheet->getHighestColumn(); //取得最大的列号<br>   $allRow = $currentSheet->getHighestRow(); //取得一共有多少行<br>   $erp_orders_id = array();  //声明数组<br>   <br>   /**从第二行开始输出,因为excel表中第一行为列名*/ <br>   for($currentRow = 1;$currentRow    <br>       /**从第A列开始输出*/ <br>     for($currentColumn= 'A';$currentColumn     <br>       $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue();/**ord()将字符转为十进制数*/<br>       if($val!=''){<br>       $erp_orders_id[] = $val; <br>       }<br>       /**如果输出汉字有乱码,则需将输出内容用iconv函数进行编码转换,如下将gb2312编码转为utf-8编码输出*/ <br>       //echo iconv('utf-8','gb2312', $val)."\t"; <br>       <br>     } <br>   } <br>   return $erp_orders_id;<br> }所有文件已经打包,感兴趣可以下载测试,多多探讨

附件 Thinkphp+PHPExcel.zip ( 3.05 KB 下载:1947 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

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.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use