脚本宝典收集整理的这篇文章主要介绍了PHP使用PHPexcel导入导出数据的方法,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了PHP使用PHPexcel导入导出数据的方法。分享给大家供大家参考,具体如下:
导入数据:
<
PRe class="
brush:
PHp;">
<>
PHP
error_reporting(E_ALL); //开启
错误
set_time_limit(0); //脚本不超时
date_default_timezone_set('Euro
PE/London'); //设置时间
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '//www.js-code
.COM/
../Classes/');//设置环境变量
/**
PHPExcel_IOFactory */
include '
PHPExcel/IOFactory.
PHP';
//$inputFileType = 'Excel5'; //这个是读 xls的
$inputFileType = 'Excel2007';//这个是计xlsx的
//$inputFileN
ame = './sampleData/example2.xls';
$inputFileName = './sampleData/
Book.xlsx';
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory w
ITh a
defined reader type of ',$inputFileType,'
';
$objReader =
PHPExcel_IOFactory
::createReader($inputFileType);
$obj
PHPExcel = $objReader->load($inputFileName);
/*
$sheet = $obj
PHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列
*/
$objWorksheet = $obj
PHPExcel->getActiveSheet();//取得总行数
$highestRow = $objWorksheet->getHighestRow();//取得总列数
echo 'highestRow='.$highestRow;
echo "
";
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex =
PHPExcel_Cell::columnIndex
FromString($highestColumn);//总列数
echo 'highestColumnIndex='.$highestColumnIndex;
echo "
";
$headtitle=array();
for ($row = 1;$row <= $highestrow;$row++)="" {="" $strs="array();" 注意highestcolumnindex的列数索引从0开始="" for="" ($col="0;$col">=>< $highestcolumnindex;$col++)="" {="" $strs[$col]="$objWorksheet-">getCellByColumnAndRow($col,$row)->getValue();
}
$info = array(
'word1'=>"$strs[0]",'word2'=>"$strs[1]",'word3'=>"$strs[2]",'word4'=>"$strs[3]",);
//
在这儿,你可以连接,你的
数据库,写入
数据库了
print_r($info);
echo '
';
}
?>
脚本宝典总结
以上是脚本宝典为你收集整理的PHP使用PHPexcel导入导出数据的方法全部内容,希望文章能够帮你解决PHP使用PHPexcel导入导出数据的方法所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。