可以先把excel文件另存为csv文件,然后写一个函数读取csv文件对文件进行操作(参考fgetcsv函数),最后rename(test.csv,test.xsl)

解决方案 »

  1.   

    主要是想保存原来EXCEL的格式(合并单元格,边框等等)。
    还有重命名的话,打开后显示的都是以“,”区分单元格的了!回不到xls格式了!
      

  2.   

    给你一个导出到Excel表的例子.
    <?php
    $mylink=mysql_connect("IP","登录名","密码");
    mysql_select_db("数据库名",$mylink);Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Content-type:application/vnd.ms-excel"); 
    Header("Content-Disposition:attachment;filename=export_excel_zsc.xls"); 
    echo $province.'省';
    if($province=='全部'){
    $pro=" and 1=1 ";
    }
    else{
    $pro=" and prov='".$province."'";
    }
    //存储显示的个数
    $coun=10;
    $date_ls=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'];
    $date_from=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 00:00:00';
    $date_to=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 23:59:59';
    $ywh=$_POST['ywh'];
    if($ywh=='全部'){
    $ywh_tj=" 1=1 ";
    $ls='所有';
    }
    else{
    $ywh_tj=" SpNum='".$ywh."'";
    $ls=$ywh;
    }
    $tx=$date_ls.'('.$ls.')业务总时长统计';
    echo $tx."\n\n";//-------------输出业务名
    $sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc";
    $result_output=mysql_query($sql_output,$mylink);
    if(mysql_num_rows($result_output)>0){
    $q=0;
    echo "业务号:"."\t";
    while($array_yh=mysql_fetch_array($result_output)){
    $ch_sec=round($array_yh['a']/60,2);
    echo $array_yh['SpNum']."业务"."\t"; }
    echo "\n";
    $sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc";
    $result_output=mysql_query($sql_output,$mylink);
    if(mysql_num_rows($result_output)>0){
    $q=0;
    echo "分钟:"."\t";
    while($array_yh=mysql_fetch_array($result_output)){
    $ch_sec=round($array_yh['a']/60,2);
    //$array_ls[$q][]=$ch_sec;
    //$array_pro[$q]=$array_yh['SpNum']."(".$ch_sec."分钟)";
    $q=$q+1;
    echo round($array_yh['a']/60,2)."\t"; }
    }
    }
    else{
    echo "没有符合的记录!";
    }
    ?>