
<php
header("Content-Type: text/html; charset=utf-8");
require_once 'dbclassphp';
require_once 'Classes/PHPExcelphp';
$objPHPExcel = new PHPExcel();
$filePath = "emailxlsx";
$arr = array();
$temparr = array();
$PHPExcel = new PHPExcel();
$PHPReader = new PHPExcel_Reader_Excel2007();
$PHPExcel = $PHPReader->load($filePath);
$currentSheet = $PHPExcel->getSheet(0);
/取得一共有多少列/
$allColumn = $currentSheet->getHighestColumn();
/取得一共有多少行/
$allRow = $currentSheet->getHighestRow();
echo $allColumn;
echo '<hr>';
echo $allRow;
echo '<hr>';
for($currentRow = 2;$currentRow<=$allRow;$currentRow++){
$temparr['usernum'] = $currentSheet->getCell('A'$currentRow)->getValue();
$temparr['price'] = $currentSheet->getCell('B'$currentRow)->getValue();
$temparr['rongliang'] = $currentSheet->getCell('C'$currentRow)->getValue();
$temparr['fujian'] = $currentSheet->getCell('D'$currentRow)->getValue();
$temparr['gerenwangpan'] = $currentSheet->getCell('E'$currentRow)->getValue();
$temparr['chaodafujian'] = $currentSheet->getCell('F'$currentRow)->getValue();
$temparr['suishenyou'] = $currentSheet->getCell('G'$currentRow)->getValue();
$temparr['chuanzhen'] = $currentSheet->getCell('H'$currentRow)->getValue();
$temparr['qiyewangpan'] = $currentSheet->getCell('I'$currentRow)->getValue();
//$arr[$currentRow-1] = $temparr;
$sql = "INSERT INTO `netease_price` (`usernum`, `price`, `rongliang`, `fujian`, `gerenwangpan`, `chaodafujian`,`suishenyou`, `chuanzhen`, `qiyewangpan`) VALUES (
'"$temparr['usernum']"',
'"$temparr['price']"',
'"$temparr['rongliang']"',
'"$temparr['fujian']"',
'"$temparr['gerenwangpan']"',
'"$temparr['chaodafujian']"',
'"$temparr['suishenyou']"',
'"$temparr['chuanzhen']"',
'"$temparr['qiyewangpan']"'
)";
mysql_query($sql);
/
自动读取
for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
$address = $currentColumn$currentRow;
echo $currentSheet->getCell($address)->getValue()"\t";
}
echo "<br />";
/
}
PHP读取excel的方法,如果你的服务器不支持COM组件,我就不好说了,下面的只是示范的例子。<PHP
$filename = "c:/spreadhseet/testxls";
$sheet1 = 1;
$sheet2 = "sheet2";
$excel_app = new COM("Excelapplication") or Die ("Did not connect");
print "Application name: {$excel_app->Application->value}n" ;
print "Loaded version: {$excel_app->Application->version}n";
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook");
$Worksheet = $Workbook->Worksheets($sheet1);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_resultn";
$Worksheet = $Workbook->Worksheets($sheet2);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_resultn";
#To close all instances of excel:
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);
>
以上就是关于现在在开发一个PHP程序,需要读取EXCEL里面的值,比如我想取出G3的值,如何处理,怎么写代码全部的内容,包括:现在在开发一个PHP程序,需要读取EXCEL里面的值,比如我想取出G3的值,如何处理,怎么写代码、php能预览excel吗、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)