Exemplo n.º 1
0
 /**
  * Export tabular data to XLS-file
  * @param array $data
  * @param string $filename
  */
 public static function arrayToXls($data, $filename = 'export', $encoding = 'utf-8')
 {
     $filePath = api_get_path(SYS_ARCHIVE_PATH) . uniqid('') . '.xlsx';
     $file = new \SplFileObject($filePath, 'w');
     $writer = new ExcelWriter($file);
     $writer->prepare();
     foreach ($data as $index => $row) {
         $writer->writeItem($row);
     }
     $writer->finish();
     DocumentManager::file_send_for_download($filePath, true, $filename . '.xlsx');
     exit;
 }
Exemplo n.º 2
0
 /**
  * Test that column names prepended at first row
  * and values have been written at second line
  * if ExcelWriter's 4-th parameter set to true
  *
  * @author  Igor Mukhin <*****@*****.**>
  */
 public function testHeaderPrependedWhenOptionSetToTrue()
 {
     $file = tempnam(sys_get_temp_dir(), null);
     $writer = new ExcelWriter(new \SplFileObject($file, 'w'), null, 'Excel2007', true);
     $writer->prepare();
     $writer->writeItem(array('col 1 name' => 'col 1 value', 'col 2 name' => 'col 2 value', 'col 3 name' => 'col 3 value'));
     $writer->finish();
     $excel = \PHPExcel_IOFactory::load($file);
     $sheet = $excel->getActiveSheet()->toArray();
     # Check column names at first line
     $this->assertEquals(array('col 1 name', 'col 2 name', 'col 3 name'), $sheet[0]);
     # Check values at second line
     $this->assertEquals(array('col 1 value', 'col 2 value', 'col 3 value'), $sheet[1]);
 }
Exemplo n.º 3
0
 public function testWriteItemWithoutSheetTitle()
 {
     $outputFile = new \SplFileObject(tempnam(sys_get_temp_dir(), null));
     $writer = new ExcelWriter($outputFile);
     $writer->prepare()->writeItem(array('first', 'last'))->finish();
 }