Format text in Excel file via PHP

前端 未结 6 492
小鲜肉
小鲜肉 2020-11-29 13:24

I\'m loading data from my database, and exporting to an Excel file via a method I found on this site: http://www.appservnetwork.com/modules.php?name=News&file=article&am

6条回答
  •  广开言路
    2020-11-29 14:01

    query($sql);
        $filename       =   "Tutoring_Log.xls";
        $contents       =   "Recap# \t Tutor Name \t Client Name \t Child Name \t Type of tutoring \t Date of Tutoring session \t Hours tutored \t Billable Travel \t Billable Additional \t Total Billable \t Client Rate \t Tutor Pay Rate \t  \n";
        $contents       .=  "  \n";
    
        while($tutorRecords = $db->fetchNextObject($totallogs)){
    
            $contents .= "".$tutorRecords->id." \t ".$tutorRecords->tutor_first_name.' '.$tutorRecords->tutor_last_name." \t ".$tutorRecords->first_name.' '.$tutorRecords->last_name." \t ".$tutorRecords->first.' '.$tutorRecords->last." \t ".$globalsConstant['type_of_tutoring'][$tutorRecords->type_of_tutoring]." \t ".date(MDY,$tutorRecords->date_of_tutoring_session)." \t ".str_replace('.',':',$tutorRecords->hours_tutored)." \t ".str_replace('.',':',$tutorRecords->billable_travel)." \t ".str_replace('.',':',$tutorRecords->billable_additional)." \t ".str_replace('.',':',$tutorRecords->total_billable)." \t ".CURRENCY.$tutorRecords->rate." \t  ".CURRENCY.$tutorRecords->tutor_pay_rate."  \t \n";
    
        }
    
        header('Content-type: application/ms-excel');
        header('Content-Disposition: attachment; filename='.$filename);
        echo $contents;
          ?>
    

提交回复
热议问题