0
엑셀 시트에 표시하고자하는 정보가 있습니다. 데이터베이스에있는 그대로 데이터를 단순하게 인쇄하고 싶지 않습니다. 형식을 제어하고 싶지만 정보를 올바르게 표시 할 수 없습니다.일부 데이터를 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++;
}
}
}
데이터를 CSV 형식으로 내보내고 Excel에서 수동 가져 오기를 수행하여 형식을 완성 해보십시오. PHP는 파일 쓰기 코드를 직접 작성하고 싶지 않은 경우에 매우 편리한 기능을 제공합니다. – EmmanuelG
코드에서 CSV를 작성하는 방법에 대해 설명하고 있지만 질문은 서식 지정을 위해 Excel 파일을 내보내는 것입니다. 이들은 매우 다른 것들입니다; http://stackoverflow.com/questions/4005814/export-from-php-to-excel에서 살펴보십시오. –