Php导出优秀的一些数据

时间:2012-05-11 04:10:32

标签: php export-to-excel

我有想要在excel示意图中显示的信息。我不想只是简单地打印数据库中的数据。我想控制格式,但我无法正确显示信息。

我的代码是:

$rep_disp = new new_report($db_link);
$rep_disp->export_summary_report_to_csv();
$out = '';
$i = 1;
foreach($rep_disp->inc_inc_t_list as $inc_t)
{
    $inc_current = '';
    $inc_current = reset($rep_disp->inc_t_curr_list[$inc_t]);
    $inc_t_amo = $rep_disp->inc_t_amo_tot[$inc_t][$inc_current];
    $out.= ','.$rep_disp->disp_inc_t_name($inc_t).',"","","","","'.$inc_t_amo.'","'.$rep_disp->disp_curr_name($inc_current).'",';
    foreach($rep_disp->inc_loc_list[$inc_t] as $inc_loc)
    {
        $k = 0;
        $out.= '\n,"","","'.$rep_disp->disp_loc_name($inc_loc).'",';

        foreach ($rep_disp->inc_cur_list[$inc_t][$inc_loc] as $inc_curr)
        {                                                                       
            /*emptying the variable to ensure a new information on each line or no display if there's none*/
            $inc_t_amo = '';
            $inc_current = '';/*this is the current currency that we are working on. It's independent from the foreach loop we use for the currency*/
            $inc_var_test = next($rep_disp->inc_t_curr_list[$inc_t]);/*will use to check if there's information to show*/
            if($inc_var_test <> '' and isset($rep_disp->inc_t_amo_tot[$inc_t][$inc_var_test]))
            {
                $inc_t_amo = $rep_disp->inc_t_amo_tot[$inc_t][$inc_var_test];
                $inc_current = $rep_disp->disp_curr_name($inc_var_test);
            }
            if($k == 0)
            {
                $out.='"'.$rep_disp->inc_loc_tot_list[$inc_t][$inc_loc][$inc_curr].'","'.$rep_disp->disp_curr_name($inc_curr).'","","'.$inc_t_amo.'","'.$inc_current.'",\n';
            }
                elseif($k > 0)
                {
                    $out.= '\n,"","","","'.$rep_disp->inc_loc_tot_list[$inc_t][$inc_loc][$inc_curr].'","'.$rep_disp->disp_curr_name($inc_curr).'","","'.$inc_t_amo.'","'.$inc_current.'",\n';
                }
            $k++;
         }
    }
}

1 个答案:

答案 0 :(得分:0)

我使用http://pear.php.net/package/Spreadsheet_Excel_Writer,虽然它看起来已不再维护了。