CI使用composer安装phpexcel并使用
phpexcel 的github地址:https://github.com/PHPOffice/PHPExcel
composer安装:composer require phpoffice/phpexcel
CI 3.x的使用方式【直接使用】:
1 |
require 'vendor/phpoffice/phpexcel/Classes/PHPExcel.php'; |
当然,更简介的使用方法是CI自身提供的功能
1 |
如果你想让 CodeIgniter 使用 Composer 的自动加载, 只需将 application/config/config.php 配置文件中的 $config['composer_autoload'] 设置为 TRUE 或者设置为你自定义的路径 |
1 |
class 你的控制器类 extends CI_Controller { ...... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
//读取示例 public function Start() { set_time_limit(90); ini_set("memory_limit", "1024M"); $input_file = "你的文档.csv"; $objPHPExcel = PHPExcel_IOFactory::load($input_file); $sheet_count = $objPHPExcel->getSheetCount(); for ($s = 0; $s < $sheet_count; $s++) { $currentSheet = $objPHPExcel->getSheet($s);// 当前页 $row_num = $currentSheet->getHighestRow();// 当前页行数 $col_max = $currentSheet->getHighestColumn(); // 当前页最大列号 // 循环从第二行开始,第一行往往是表头 for($i = 2; $i < $row_num+1; $i++) { $cell_values = array(); for($j = 'A'; $j < $col_max; $j++) { $address = $j . $i; // 单元格坐标 $cell_values[] = $currentSheet->getCell($address)->getFormattedValue(); } } } } |
噢!评论已关闭。