phpexcel怎么读取excel文件?phpexcel读取xls文件的例子
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-07-25 08:51:37
asal
1151 orang telah melayarinya
-
-
error_reporting(E_ALL);
-
- date_default_timezone_set('Asia/ShangHai');
-
- /** PHPExcel_IOFactory */
- require_once '../Classes/PHPExcel/IOFactory.php';
-
- // Check prerequisites
- if (!file_exists("31excel5.xls")) {
- exit("not found 31excel5.xls.\n");
- }
-
- $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿)
- $PHPExcel = $reader->load("31excel5.xls"); // 载入excel文件
- $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
- $highestRow = $sheet->getHighestRow(); // 取得总行数
- $highestColumm = $sheet->getHighestColumn(); // 取得总列数
- $highestColumm= PHPExcel_Cell::columnIndexFromString($colsNum); //字母列转换为数字列 如:AA变为27
-
- /** 循环读取每个单元格的数据 */
- for ($row = 1; $row for ($column = 0; $column $columnName = PHPExcel_Cell::stringFromColumnIndex($column);
- echo $columnName.$row.":".$sheet->getCellByColumnAndRow($column, $row)->getValue()."
";
- }
- }
- ?>
复制代码
例2,简化后的读取excel文件的方法:
-
-
error_reporting(E_ALL);
-
- date_default_timezone_set('Asia/ShangHai');
-
- /** PHPExcel_IOFactory */
- require_once '../Classes/PHPExcel/IOFactory.php';
-
- // Check prerequisites
- if (!file_exists("31excel5.xls")) {
- exit("not found 31excel5.xls.\n");
- }
-
- $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿)
- $PHPExcel = $reader->load("31excel5.xls"); // 载入excel文件
- $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
- $highestRow = $sheet->getHighestRow(); // 取得总行数
- $highestColumm = $sheet->getHighestColumn(); // 取得总列数
-
- /** 循环读取每个单元格的数据 */
- for ($row = 1; $row for ($column = 'A'; $column $dataset[] = $sheet->getCell($column.$row)->getValue();
- echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."
";
- }
- }
- ?>
复制代码
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Isu terkini
-
2025-03-21 13:39:34
-
2025-03-21 13:38:34
-
2025-03-21 13:37:19
-
2025-03-21 13:35:24
-
2025-03-21 13:34:32
Topik-topik yang berkaitan
Lagi>