正文开始 LR主页 回首页 thinkphp PHPEXCEL 扩展包下载和导入excel示例
正文开始 依赖2个列互转函数 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26, 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13, 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26 );
} file_put_contents($move_to_file, $fileBase64);
//载入文件 $PHPExcel = $PHPReader->load($move_to_file); //获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推 $sheet = $PHPExcel->getSheet(0); // 取得总行数 $highestRow = $sheet->getHighestDataRow(); // 取得总列数 $highestColumn = $sheet->getHighestDataColumn(); $highestColumnNum = Excel::columnIndexFromString($highestColumn); //循环读取excel文件,读取一条,插入一条 $data=array(); //从第一行开始读取数据 for($j=1;$j<=$highestRow;$j++){ //从A列读取数据 for($k=0; $k<=$highestColumnNum; $k++){ $cellName = Excel::stringFromColumnIndex($k); // 读取单元格 $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$cellName$j")->getValue(); } } print_r(json_encode($data)); exit; /upload/post_files/3wyltaJgRppq0AZy.txt vendor扩展下载后 .txt格式改为.zip 解压到/vendor/目录下 如: \vendor\PHPExcel\PHPExcel.php \vendor\PHPExcel\PHPExcel 正文结束 PHP接口(interface)和抽象类(abstract) php excel的列名字:字母和数字互转 ©2007 正文结束 |
PHP接口(interface)和抽象类(abstract) | php excel的列名字:字母和数字互转 |