<?php
header("Content-Type:text/html;charset=utf-8");
// ini_set('memory_limit','200M'); //設置文件上傳大小
require_once 'PHPExcel.php';
require_once 'PHPExcel/IOFactory.php';
$reader = PHPExcel_IOFactory::createReader('Excel2007'); // 讀取 excel 文件方式 此方法是讀取excel2007之前的版本 excel2007 為讀取2007以后的版本 也可以查\Classes\PHPExcel\Reader 文件夾中的類(為所有讀取類,需要哪個填上哪個就行)
$resource = 'test.xlsx';
if (! file_exists( $resource)) {
exit(" $resource is not exists.\n");
}
$PHPExcel = $reader->load("test.xlsx"); // 文件名稱
$sheet = $PHPExcel->getSheet(0); // 讀取第一個工作表從0讀起
$highestRow = $sheet->getHighestRow(); // 取得總行數
$highestColumn = $sheet->getHighestColumn(); // 取得總列數
echo $highestRow. $highestColumn;
// 根據自己的數據表的大小修改
$arr = array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M', 14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z');
// 每次讀取一行,再在行中循環每列的數值
for ( $row = 1; $row <= $highestRow; $row++) {
for ( $column = 1; $arr[ $column] != 'D'; $column++) {
$val = $sheet->getCellByColumnAndRow( $column, $row)->getValue();
$list[ $row][] = $val;
}
}
echo "<pre>". print_r( $list)."</pre>";
?>
header("Content-Type:text/html;charset=utf-8");
// ini_set('memory_limit','200M'); //設置文件上傳大小
require_once 'PHPExcel.php';
require_once 'PHPExcel/IOFactory.php';
$reader = PHPExcel_IOFactory::createReader('Excel2007'); // 讀取 excel 文件方式 此方法是讀取excel2007之前的版本 excel2007 為讀取2007以后的版本 也可以查\Classes\PHPExcel\Reader 文件夾中的類(為所有讀取類,需要哪個填上哪個就行)
$resource = 'test.xlsx';
if (! file_exists( $resource)) {
exit(" $resource is not exists.\n");
}
$PHPExcel = $reader->load("test.xlsx"); // 文件名稱
$sheet = $PHPExcel->getSheet(0); // 讀取第一個工作表從0讀起
$highestRow = $sheet->getHighestRow(); // 取得總行數
$highestColumn = $sheet->getHighestColumn(); // 取得總列數
echo $highestRow. $highestColumn;
// 根據自己的數據表的大小修改
$arr = array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M', 14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z');
// 每次讀取一行,再在行中循環每列的數值
for ( $row = 1; $row <= $highestRow; $row++) {
for ( $column = 1; $arr[ $column] != 'D'; $column++) {
$val = $sheet->getCellByColumnAndRow( $column, $row)->getValue();
$list[ $row][] = $val;
}
}
echo "<pre>". print_r( $list)."</pre>";
?>
轉自 http://yuninglovekefan.blog.sohu.com/169872265.html