0

I have information that I want to display in a 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++;
         }
    }
}
2
  • Would you be willing to consider exporting the data as a CSV and doing a manual import in excel to complete the formatting? PHP has some pretty handy functions for that if you dont want to manually write file writing code. Commented May 11, 2012 at 4:16
  • Your code is describing writing a CSV, but your question is about exporting an Excel file for formatting. These are very different things; take a look at stackoverflow.com/questions/4005814/export-from-php-to-excel Commented May 11, 2012 at 4:19

1 Answer 1

0

I use http://pear.php.net/package/Spreadsheet_Excel_Writer, although it looks like it's no longer maintained.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.