[英]Php export to excel some data
I have information that I want to display in a excel scheet. 我有要在excel scheet中显示的信息。 I don't want to just plainly print the data as it is in the database.
我不想只是简单地打印数据库中的数据。 I want to control the formatting, but I can't get it to display the information right.
我想控制格式,但无法正确显示信息。
My code is : 我的代码是:
$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++;
}
}
}
我使用http://pear.php.net/package/Spreadsheet_Excel_Writer ,尽管看起来好像不再维护了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.