コード例 #1
0
ファイル: Action.php プロジェクト: anunay/stentors
 public function toPdfAction()
 {
     if (empty($this->filename)) {
         throw new Exception('You must define $this->filename for the output filename');
     }
     if (empty($this->select)) {
         throw new Exception('You must define $this->select a select statement');
     }
     if (empty($this->fields)) {
         throw new Exception('You must define $this->fields as an array with all the fields');
     }
     $this->disableLayout();
     $this->disableView();
     if ($this->select) {
         if ($this->filters) {
             $filters = $this->filters;
             foreach ($filters as $key => $filter) {
                 $filter_val = $this->_getParam($key);
                 if (!empty($filter_val)) {
                     $this->select->where("{$filter['associatedTo']} = ?", $filter_val);
                 }
             }
         }
         if ($this->_getParam('order')) {
             if (in_array($this->_getParam('order'), $this->fields)) {
                 $direction = 'ASC';
                 if (in_array($this->_getParam('order-direction'), array('ASC', 'DESC'))) {
                     $direction = $this->_getParam('order-direction');
                 }
                 $this->select->order("{$this->_getParam('order')} {$direction}");
             }
         }
         $searchfor = $this->_getParam('searchfor');
         if ($searchfor) {
             $searching_on = array();
             $search_keywords = explode(' ', $searchfor);
             foreach ($this->tables as $table => $columns) {
                 foreach ($columns as $column) {
                     array_push($searching_on, $this->_db->quoteInto("{$table}.{$column} LIKE ?", "%{$searchfor}%"));
                     foreach ($search_keywords as $keyword) {
                         array_push($searching_on, $this->_db->quoteInto("{$table}.{$column} LIKE ?", "%{$keyword}%"));
                     }
                 }
             }
             if (!empty($searching_on)) {
                 $this->select->where(implode(' OR ', $searching_on));
             }
         }
         $results = $this->_db->fetchAll($this->select);
         $objPHPExcel = new PHPExcel();
         $objPHPExcel->setActiveSheetIndex(0);
         foreach (array_keys($this->fields) as $i => $field_value) {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $field_value);
         }
         $key = 2;
         foreach ($results as $value) {
             foreach (array_keys($this->fields) as $i => $field_value) {
                 if (!empty($value[$field_value])) {
                     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, $key, $value[$field_value]);
                 }
             }
             $key++;
         }
         // load the appropriate IO Factory writer
         $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
         // output the appropriate headers
         header("Content-type: application/pdf");
         header("Content-Disposition: attachment;filename={$this->filename}");
         // output the file
         $objWriter->save('php://output');
         exit;
     }
 }
コード例 #2
0
		function generateBook($book, $format) {

			$this->book= $book;			
			
			if (!$book->bookId)
				$bookName= "spreadsheet-1";	
			else	
				$bookName= "spreadsheet-$book->bookId";
							
			$filename= "default-".rand(1,9999);
			

			/*SET SPREADSHEET PROPERTIES*/
			if ($format!= "ods"){

				$this->objPHPExcel = new PHPExcel();
				$this->objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
				$this->objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
				$this->objPHPExcel->getProperties()->setTitle("Test Document");
				$this->objPHPExcel->getProperties()->setSubject("Test Document");
				$this->objPHPExcel->getProperties()->setDescription("Test document generated using PHP classes.");
				$this->objPHPExcel->getProperties()->setKeywords("office php");
				$this->objPHPExcel->getProperties()->setCategory("Test result file");

			}
			else{
				$this->objPHPOds= new PHPOds(); //create a new ods file
			}

			/*GENERATE THE SHEETS*/
			$this->_generateSheets($format);


			global $cnf;
			$currentDir= $cnf['path']['Temp']."/";  // Get the Storage Folder


			switch($format){

				case "ods":
							saveOds($this->objPHPOds,"$filename.$format"); //save the object to a ods file
							break;

				case "pdf":
							$objWriter1 = new PHPExcel_Writer_PDF($this->objPHPExcel);
							$objWriter1->writeAllSheets();
							$objWriter1->setTempDir($currentDir);
							$objWriter1->save("$filename.$format");	//save the object to a pdf file
							break;

				case "xls":
							$objWriter2 = new PHPExcel_Writer_Excel5($this->objPHPExcel);
							$objWriter2->setTempDir($currentDir);
							$objWriter2->save("$filename.$format");	//save the object to a xls file
							break;

				case "xlsx":
							$objWriter3 = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel2007');
							$objWriter3->save($currentDir."$filename.$format"); //save the object to a xlsx file
							break;

				case "csv":
							$objWriter4 = new PHPExcel_Writer_CSV($this->objPHPExcel);
							//$objWriter4->setTempDir($currentDir);
							$objWriter4->setDelimiter(';');
							$objWriter4->setEnclosure('');
							$objWriter4->setLineEnding("\r\n");
							$objWriter4->save("$filename.$format");	//save the object to a CSV file
							break;
							
				case "html":
							$objWriter5 = new PHPExcel_Writer_HTML($this->objPHPExcel);
							$objWriter5->writeAllSheets();
							//$objWriter5->setTempDir($currentDir);
							$objWriter5->save("$filename.$format");	//save the object to a HTML file
							break;
							

			}

			if ($format != "ods")
				$this->_send("$filename.$format", $format, $bookName);

		}
コード例 #3
0
ファイル: crear_pdf.php プロジェクト: oalba/facturanav
if ($laboral != NULL) {
    $objPHPExcel->setActiveSheetIndex(0)->mergeCells('B44:E44');
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B44', $laboral);
}
if ($kutxa != NULL) {
    $objPHPExcel->setActiveSheetIndex(0)->mergeCells('B45:E45');
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B45', $kutxa);
}
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A48', 'Subtotal')->setCellValue('A49', '=SUM(G16:G46)')->setCellValue('C48', 'IVA ' . $iva . '%')->setCellValue('C49', '=A49*' . $iva . '%')->setCellValue('E49', 'TOTAL:')->setCellValue('F49', '=A49+C49')->setCellValue('A51', 'De conformidad con la Ley Orgánica de Protección de Datos de Carácter Personal 15/1999, le recordamos que sus datos han sido incorporados en un fichero de datos de carácter personal del que es titular ******* **** *******, debidamente registrado ante la AEPD y cuya finalidad es de gestión de datos de clientes para tareas contable, fiscal y administrativas, Así mismo, le informamos que sus datos podrán ser cedidos, siempre protegiendo los datos adecuadamente, a: administración tributaria y bancos, cajas de ahorros y cajas rurales. Puede ejercitar sus derechos de Acceso, Rectificación, Cancelación y Oposición en ******* ** - *****, ******* (*********) o enviando un correo electrónico a *****.****@hotmail.com.');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&6&ArialDe conformidad con la Ley Orgánica de Protección de Datos de Carácter Personal 15/1999, le recordamos que sus datos han sido incorporados en un fichero de datos de carácter personal del que es titular ******* **** *******, debidamente registrado ante la AEPD y cuya finalidad es de gestión de datos de clientes para tareas contable, fiscal y administrativas, Así mismo, le informamos que sus datos podrán ser cedidos, siempre protegiendo los datos adecuadamente, a: administración tributaria y bancos, cajas de ahorros y cajas rurales. Puede ejercitar sus derechos de Acceso, Rectificación, Cancelación y Oposición en ******* ** - *****, ******* (*********) o enviando un correo electrónico a *****.****@hotmail.com.');
// Rename worksheet
$worksheet->setTitle('Factura');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
//$objPHPExcel->setActiveSheetIndex(0);
// Save PDF file
if (!PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) {
    die('NOTICE: Please set the ' . $rendererName . ' and ' . $rendererLibraryPath . 'values' . '<br />' . 'at the top of this script as appropriate for your directory structure');
}
/*header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="'.$numero.'.pdf"');
header('Cache-Control: max-age=0');*/
$objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$objWriter->save('C:\\facturas/' . $numero . '.pdf');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
//}
mysql_close($dp);
header("Location: ../index.php");
コード例 #4
0
//$objPHPExcel->getActiveSheet()->getStyle()->get
//$objPHPExcel->getActiveSheet()->getStyle()->getFont()->setColor(PHPExcel_Style_Color::setRGB(););
$objPHPExcel->getActiveSheet()->getStyle()->getFont()->setItalic();
$objPHPExcel->getActiveSheet()->getStyle()->getFont()->setSize();
$objPHPExcel->getActiveSheet()->getStyle()->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
// Rename sheet
//echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->createSheet();
// Save Excel 2007 file
//echo date('H:i:s') . " Write to Excel2007 format\n";
//echo "<br>" . __FILE__ . "<br>";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$pdf = new PHPExcel_Writer_PDF($objPHPExcel);
$pdf->save("pdfprueba.pdf");
// Echo memory peak usage
//echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
// Echo done
//echo date('H:i:s') . " Done writing file.\r\n";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename= prueba.xlsx");
header("Content-Transfer-Encoding: binary ");
readfile("01simple.xlsx");
コード例 #5
-1
ファイル: Output.php プロジェクト: unionbt/hanpaimall
 public static function excel($data, $ext = 'xlsx', $filepath = TRUE)
 {
     $excel = new \PHPExcel();
     $excel->setActiveSheetIndex(0);
     $sheet = $excel->getActiveSheet();
     array_walk($data, function (&$v) {
         foreach ($v as $key => $value) {
             !is_scalar($value) && ($v[$key] = @strval($value));
         }
     });
     $sheet->fromArray($data);
     $filepath == TRUE && ($filepath = tempnam(storage_path('utils'), 'excel'));
     switch (strtolower($ext)) {
         case 'xlsx':
             $objWriter = new \PHPExcel_Writer_Excel2007($excel);
             break;
         case 'xls':
             $objWriter = new \PHPExcel_Writer_Excel5($excel);
             break;
         case 'csv':
             $objWriter = new \PHPExcel_Writer_CSV($excel);
             break;
         case 'pdf':
             $objWriter = new \PHPExcel_Writer_PDF($excel);
             break;
         default:
             # code...
             break;
     }
     $objWriter->save($filepath);
     //@unlink($filepath);
     return $filepath;
 }