标签:cti classes filename 一段 http str blog inpu mat
首先要引入类库
require_once dirname(__FILE__) . ‘/../Classes/PHPExcel.php‘; require_once dirname(__FILE__) . ‘/../Classes/PHPExcel/IOFactory.php‘;
set_time_limit(900);//设置超时 ini_set("memory_limit", "1024M");//使用内存限制
$inputFileName = ‘D:/wamp/vhosts/a.8g.com/Upload/111.xls‘; $inputFileType = ‘Excel5‘;//写入有用 $objPHPExcel = \PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); var_dump($sheetData); $sheet_count = $objPHPExcel->getSheetCount(); for ($s = 0; $s <$sheet_count; $s++) { $currentSheet = $objPHPExcel->getSheet($s);// 当前页 $row_num = $currentSheet->getHighestRow();// 当前页行数 $row_num = 10; $col_max = $currentSheet->getHighestColumn(); // 当前页最大列号 // // 循环从第二行开始,第一行往往是表头 // for($i = 2; $i <= $row_num; $i++) // { // $cell_values = array(); // for($j = ‘A‘; $j <$col_max; $j++) // { // $address = $j . $i; // 单元格坐标 // $cell_values[] = $currentSheet->getCell($address)->getFormattedValue(); // } // // //看看数据 // print_r($cell_values); // } }
我thinkphp里面的一段代码
public function getExcelData($filePath) { vendor(‘PHPExcel.PHPExcel.IOFactory‘,‘‘,‘.php‘); $inputFileType = ‘Excel5‘; $objPHPExcel = \PHPExcel_IOFactory::load($filePath); // 读取规则 $sheet_read_arr = array(); $sheet_read_arr["Page1"] = array("A","K","L","S","M","T"); //$sheet_read_arr["sheet2"] = array("A","B","C","D","F"); // 循环所有的页 foreach ($sheet_read_arr as $key => $val) { $currentSheet = $objPHPExcel->getSheetByName($key);// 通过页名称取得当前页 $row_num = $currentSheet->getHighestRow();// 当前页行数 $result = array(); // 循环从第二行开始,第一行往往是表头 for ($i = 1; $i <= $row_num; $i++) { $cell_values = array(); foreach ($val as $cell_val) { $address = $cell_val . $i;// 单元格坐标 // 读取单元格内容 $cell_values[] = $currentSheet->getCell($address)->getFormattedValue(); } // 看看数据 $result[] = $cell_values; } return $result; }
参:http://blog.csdn.net/ning521513/article/details/55257925
标签:cti classes filename 一段 http str blog inpu mat
原文地址:http://www.cnblogs.com/fps2tao/p/8013155.html