コード例 #1
0
 /**
  * Download file
  * @return void
  */
 public function download()
 {
     Functions::forceDownload($this->file->dump(), $this->file->getFileName(), $this->file->getFileExtension());
 }
コード例 #2
0
 /**
  * Download Xls File
  */
 public function download()
 {
     $doc = new PHPExcel();
     $doc->setActiveSheetIndex(0);
     // Width
     if (array_key_exists('width', $this->styles) && !empty($this->styles['width']) && is_array($this->styles['width'])) {
         foreach ($this->styles['width'] as $widthColumn => $widthValue) {
             $doc->getActiveSheet()->getColumnDimension($widthColumn)->setAutoSize(false)->setWidth($widthValue);
         }
     }
     // Background color
     if (array_key_exists('background_color', $this->styles) && !empty($this->styles['background_color']) && is_array($this->styles['background_color'])) {
         foreach ($this->styles['background_color'] as $columnRange => $colorHex) {
             $doc->getActiveSheet()->getStyle($columnRange)->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $colorHex))));
         }
     }
     // Font color
     if (array_key_exists('font_color', $this->styles) && !empty($this->styles['font_color']) && is_array($this->styles['font_color'])) {
         foreach ($this->styles['font_color'] as $columnRange => $colorHex) {
             $doc->getActiveSheet()->getStyle($columnRange)->applyFromArray(array('font' => array('color' => array('rgb' => $colorHex))));
         }
     }
     // Alignment
     if (array_key_exists('align', $this->styles) && !empty($this->styles['align']) && is_array($this->styles['align'])) {
         foreach ($this->styles['align'] as $columnRange => $alignment) {
             $doc->getActiveSheet()->getStyle($columnRange)->applyFromArray(self::$alignment[$alignment]);
         }
     }
     // Alignment
     $index = 1;
     foreach ($this->getRows() as $row) {
         $doc->getActiveSheet()->fromArray(array($row), null, 'A' . $index);
         $index++;
     }
     $fileName = !empty($this->getFileName()) ? $this->getFileName() : Functions::generateRandomString(10);
     $file = $fileName . '.' . $this->getFileExtension();
     $writer = PHPExcel_IOFactory::createWriter($doc, 'Excel5');
     header('Content-type: ' . $this->getContentType());
     header('Content-Disposition: attachment; filename="' . $file . '"');
     return $writer->save('php://output');
 }