现在在开发一个PHP程序,需要读取EXCEL里面的值,比如我想取出G3的值,如何处理,怎么写代码?

如果能帮助我解决,可以发吉利的微信红包... 如果能帮助我解决,可以发吉利的微信红包 展开
 我来答
sunny晴天62
2017-03-16 · TA获得超过129个赞
知道答主
回答量:275
采纳率:0%
帮助的人:97.9万
展开全部
<?php
header("Content-Type: text/html; charset=utf-8");
require_once 'db.class.php';
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$filePath = "email.xlsx";
$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 />";
*/
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式