lundi 22 juin 2020

export data into excel with horizontal columns using php

Please find the screenshot for format displaying in excel sheet. I need contact number to display beside Name.

foreach ($questions as  $question) {
   $string .= '<tr><th>'.$question->question_order.'</th><th>'.$question->question_text.'</th></tr>';
   if ($question->widget->name == 'select_one'||$question->widget->name == 'dropdown'||$question->widget->name == 'select_many'){
      $string .='<tr><th>Option</th><th>Count</th><th>Percentage</th></tr>';
      if (!empty($question->rows)) {
         foreach($question->rows()->orderBy('order','asc')->get() as $row){
            $string .= '<tr>';
            $string .= '<td>'.$row->name.'</td>';
            $string .= '<td>'.getAnswerCount($row->id).'</td>';
            $string .= '<td>'.getAnswerPercentage($row->id) .'</td>';
            $string .= '</tr>';
         }
      }
   } elseif ($question->widget->name == 'comment_box') {
      $string .= '<tr><th>Date</td><th>Comment</th></tr>';
      $allComments = getAllComments($question->id);
      foreach($allComments as $comment){
         $string .= '<tr>';
         $string .= '<td>'.$comment->completed_at.'</td>';
         $string .= '<td>'.$comment->comment.'</td>';
         $string .= '</tr>';
      }
   }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire