title: PhpExcel export data from a website to CSV file
body: <p>I want to export data from orangehrm attendance report to csv file by using phpexcel but I don't know how to do it: </p>
  
  <pre><code>$records = array();
                  foreach ($empRecords as $employee) {
                      $hasRecords = false;
  
                      $attendanceRecords = $employee-&gt;getAttendanceRecord();
                      $total = 0;
                      foreach ($attendanceRecords as $attendance) {
                          $from = $this-&gt;date . " " . "00:" . "00:" . "00";
                          $end = $this-&gt;date2 . " " . "23:" . "59:" . "59";
                          if (strtotime($attendance-&gt;getPunchInUserTime()) &gt;= strtotime($from) &amp;&amp; strtotime($attendance-&gt;getPunchInUserTime()) &lt;= strtotime($end)) {
                              if ($attendance-&gt;getPunchOutUtcTime()) {
                                  $total = $total + round((strtotime($attendance-&gt;getPunchOutUtcTime()) - strtotime($attendance-&gt;getPunchInUtcTime())) / 3600, 2);
                              }
                              $records[] = $attendance;
                              $hasRecords = true;
                          }
                      }
  
                      if ($hasRecords) {
                          $last = end($records);
                          $last-&gt;setTotal($total);
                      } else {
                          $attendance = new AttendanceRecord();
                          $attendance-&gt;setEmployee($employee);
                          $attendance-&gt;setTotal('---');
                          $records[] = $attendance;
                      }
                  }
                      // Algorithm to export filtered/ searched data
                      if($post['export'] == '1'){
  
                      //require_once 'PHPExcel/Reader/Excel15.php';
                      //require_once 'PHPExcel/Reader/Excel2007.php';
  
                      require_once 'PHPExcel/IOFactory.php';
                      require_once 'PHPExcel.php';
                      $objPHPExcel = new PHPExcel();
                      $objActSheet = $objPHPExcel-&gt;getActiveSheet();
                      $objActSheet-&gt;setTitle('Staff AttendanceRecord');
  
  
                      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                      $objWriter-&gt;save('Attendance.xslx');
  
  
  
      }
  </code></pre>