Large File in Oracle

Topics: User Forum
Jul 29, 2010 at 10:29 AM

Hi there

i have problem with PHPExcel and Oci8 connection.

I tried to link records fetched through an Oracle connection and phpExcel.

The code seems to be correct, and the Excel is successfully created.

When i open the file, it results malformed or corrupted. 

The data shown in the file, are correct but there are also a lot of cells full of strage chars,

numbers and symbol.

Here the code. It's quite simple, and looks like the examples packed in the PhpExcel zip.

Thx in Advance. Studio148 : )

 

<?php

  /** Error reporting */
  error_reporting(E_ALL);
  /** PHPExcel */
  require_once '../Classes/PHPExcel.php';	
  
  
  include("connection.php");
 
	// Create new PHPExcel object
	$objPHPExcel = new PHPExcel();

	// Set properties
	$objPHPExcel->getProperties()->setCreator("Studio148")
							 ->setLastModifiedBy("Studio148")
							 ->setTitle("Office 2007 XLSX Test Document")
							 ->setSubject("Office 2007 XLSX Test Document")
							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords("office 2007 openxml php")
							 ->setCategory("Test result file");
  
  
	
	// Create a first sheet

	$objPHPExcel->setActiveSheetIndex(0);
	
	
  
    $stmt = oci_parse($conn, "SELECT  TICKET_NO, DATA_NOTIFICA, STATO, INDIRIZZO, RIF_TELEFONICO, DATA_RISOLUZIONE, DATA_CHIUSURA FROM MHT_TICKET");
    oci_execute($stmt, OCI_DEFAULT);

	
	if($stmt){
	
		$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Ticket Number');
		$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Data Notifica');
		$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Stato');
		$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Indirizzo');
		$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Telefono');
		$objPHPExcel->getActiveSheet()->setCellValue('F1', 'Data Risoluzione');
		$objPHPExcel->getActiveSheet()->setCellValue('G1', 'Data Chiusura');
	
		$count = 1;

		$variabili = null;
		$variabili = Array('TICKET_NO','DATA_NOTIFICA','STATO','INDIRIZZO','RIF_TELEFONICO','DATA_RISOLUZIONE','DATA_CHIUSURA');

		while ( $entry=oci_fetch_array($stmt) ) {
		
			foreach($variabili as $variabile){
				$$variabile = $entry[$variabile];
				//echo $entry[$variabile];
			}
			$count++;
			
			$objPHPExcel->getActiveSheet()->setCellValue('A' . $count, $TICKET_NO);
			$objPHPExcel->getActiveSheet()->setCellValue('B' . $count, $DATA_NOTIFICA);
			$objPHPExcel->getActiveSheet()->setCellValue('C' . $count, $STATO);
			$objPHPExcel->getActiveSheet()->setCellValue('D' . $count, $INDIRIZZO);
			$objPHPExcel->getActiveSheet()->setCellValue('E' . $count, $RIF_TELEFONICO);
			$objPHPExcel->getActiveSheet()->setCellValue('F' . $count, $DATA_RISOLUZIONE);
			$objPHPExcel->getActiveSheet()->setCellValue('G' . $count, $DATA_CHIUSURA);
			
		}
		
		
		
		
	}
	
	
	oci_free_statement($stmt);
	oci_close($conn);
	
	// Set title row bold

	$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setBold(true);


	// Set active sheet index to the first sheet, so Excel opens this as the first sheet
	$objPHPExcel->setActiveSheetIndex(0);
	
	// Redirect output to a client’s web browser (Excel5)
	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="01simple.xls"');
	header('Cache-Control: max-age=0');

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
	exit;
	
    
?>



 

 

  

Coordinator
Jul 30, 2010 at 1:40 PM

What character set are you using for the data in your Oracle database?

Aug 3, 2010 at 10:04 PM
Hi Mark and thx for your reply I solved !! Oracle connection was ok so the character set used in the db. The problem was this: include("connection.php"); Changing this line of code with all the code in my "connection.php" file, PHPExcel works properly. I don't understand why include('...') generate this behaviour in PHPExcel O_O Studio148 : )