用PHPExcel,PHPExcel是相当强大的 MS Office Excel 文档生成类库.
看一下其中的开发文档你就会用了.
require_once '../Classes/PHPExcel/IOFactory.php';
$objReader-setReadDataOnly(true);
$objPHPExcel = $objReader-load("test.xlsx");
$objWorksheet = $objPHPExcel-getActiveSheet();
echo 'table' . "\n";
foreach ($objWorksheet-getRowIterator() as $row) {
echo 'tr' . "\n";
$cellIterator = $row-getCellIterator();
$cellIterator-setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo 'td' . $cell-getValue() . '/td' . "\n";
}
echo '/tr' . "\n";
echo '/table' . "\n";
你如果会PHP就很容易 这个就是表单提交 PHP接受表单提交的参数然后入库 就OK
修改就执行UPDATE sql语句
先整个最基础的代码,理解了这个,后面的就非常简单了
import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.IOFactory");
$sheet?=?$objPHPExcel-getSheet(0);
$highestRow?=?$sheet-getHighestRow();?//?取得总行数
$highestColumn?=?$sheet-getHighestColumn();?//?取得总列数
表格内容:
再给大家整个一点难度的,先说下思路.
①上传excel文件,得到它的地址
实例代码演示:
public?function?upload(){
$files?=?$_FILES['exl'];
//?exl格式,否则重新上传
if($files['type']?!='application/vnd.ms-excel'){
$this-error('不是Excel文件,请重新上传');?
//?上传
$upload?=?new?\Think\Upload();//?实例化上传类
$upload-exts?=??array('xls');//?设置附件上传类型
$upload-rootPath?=??'./Upload/';?//?设置附件上传根目录
$upload-savePath?=??'excel/';?//?设置附件上传(子)目录
//$upload-subName?=??array('date',?'Ym');
$upload-subName?=??'';
//?上传文件?
$info?=?$upload-upload();
$file_name?=?$upload-rootPath.$info['exl']['savepath'].$info['exl']['savename'];
$exl?=?$this-import_exl($file_name);
//?去掉第exl表格中第一行
unset($exl[0]);
//?清理空数组
foreach($exl?as?$k=$v){
if(empty($v)){
unset($exl[$k]);
}?
};
//?重新排序
sort($exl);
$count?=?count($exl);
//?检测表格导入成功后,是否有数据生成
if($count1){
$this-error('未检测到有效数据');?
//?开始组合数据
$goods[$k]['goods_sn']?=?$v;
//?查询数据库
$where['goods_sn']?=?array('like','%'.$v.'%');
$res?=?M('goods')-where($where)-find();
$goods[$k]['goods_name']?=?$res['goods_name'];
$goods[$k]['goods_thumb']?=?$res['goods_thumb'];
if($res){
//?是否匹配成功?
$goods[$k]['is_match']?=?'1';
$f?+=?1;
}else{
//?匹配失败
$goods[$k]['is_match']?=?'0';
$w?+=?1;
//?实例化数据
$this-assign('goods',$goods);
//print_r($f);
//?统计结果
$total['count']?=?$count;
$total['success']?=?$f;
$total['error']?=?$w;
$this-assign('total',$total);
//?删除Excel文件
unlink($file_name);
/*?处理上传exl数据
*?$file_name?文件路径
*/
public?function?import_exl($file_name){
import("Org.Util.PHPExcel");?//?这里不能漏掉
for($i=1;$i$highestRow+1;$i++){
$data[]?=?$objPHPExcel-getActiveSheet()-getCell('A'.$i)-getValue();?
return?$data;?
有问题一定要及时弄清楚
写个简单的吧
a.php
form method="post" action="b.php"
input type="text" name="test" value=""这是你要提交的数据
input type="submit" value="提交"
/form
b.php
echo $_POST['test'];
打印a提交过来的数据,如果有数据你就自己写sql语句存入数据库就好了
js提交啊, 有form标签包住数据没, 给form设置一个id和name都为form1,
那么可以这样提交: document.forms['form1'].submit();
//第一步
$con
=
//第二步
mysql_select_db('rankingme',$conn);
//第三步
$sql="insert
into
lili
(name,sex,et,hobby,photo,tel,address,content,time)
values
($name,$sex,$et,$hobby,$photo,$tel,$address,$content,$time)"
//第四步
mysql_query($sql);
//第五步
mysql_close($con);
以上就是土嘎嘎小编为大家整理的php上传表格数据到后台相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!