<style>
body{margin:0}
li{list-style-type:none;cursor:pointer}
.execl{
display:flex;
justify-content:space-between;
}
.execl div{
display:flex;
flex-direction:column;
}
.file{
display:flex;
justify-content:space-around;
}
button{height:20}
</style>
<div class=file>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="上传" />
</form>
<button>
导出
</button>
</div>
<script src=jq.js></script>
<script>
$('button').click(function(){
location.href='upload/test.xlsx'
})
</script>
<?php
if(isset($_FILES["file"]["name"])){
$type=explode('.',$_FILES["file"]["name"])[1];
if( $type=='xls' || $type=='xlsx'){
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
}
}
require 'Classes/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load('test.xlsx'); //加载excel文件
require_once 'Classes/PHPExcel.php';
$sheet=$objPHPExcel->getSheet(1);//获取第一个工作表
$highestRow=$sheet->getHighestRow();//取得总行数
$highestColumn=$sheet->getHighestColumn(); //取得总列数
$str="<div>";
for($k='A';$k<=$highestColumn;$k++){
for($j=1;$j<=$highestRow;$j++){//从第一列开始读取数据
$value=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
$first=$objPHPExcel->getActiveSheet()->getCell($k.'1')->getValue();
if($first=='重量' && $value!='重量'){
$weight[]=$value;
}
if($first=='运费' && $value!='运费'){
$w=$weight[$j-2];
0<$w && $w<=0.5 ? $value=0.2 : '' ;
0.5<$w && $w<=1 ? $value=1 : '' ;
}
$k=='A' && $j!=1 ? $value=date('m-d') : '' ;
if($j==$highestRow){
$str.="<li>".$value."</li></div><div>";
}else{
$str.="<li>".$value."</li>";
}
}
}
echo "<div class=execl>".$str."</div>";