Export to excel
I am having a small problem publishing to excel
PHP Code:
<?php
error_reporting ( E_ALL );
date_default_timezone_set ( 'America/New_York' );
/** PHPExcel */
require_once 'classes/opendb.php' ;
require_once 'classes/class.database.php' ;
require_once 'classes/PHPExcel.php' ;
// Create new PHPExcel object
$database = new database ();
$objPHPExcel = new PHPExcel ();
$alphas = range ( 'A' , 'Z' );
$tablename = $_GET [ 't' ];
$filenum = $_GET [ 'f' ];
$stat = $_GET [ 's' ];
$end = $_GET [ 'e' ];
$data = $database -> get_table_headers ( $tablename );
$output = "<table> \n" ;
$output .= "<tr> \n" ;
for( $i = 0 ; $i < count ( $data ); $i ++){
$output .= "<td>" . $data [ $i ][ 0 ] . "</td> \n" ;
}
$output .= "</tr>\n" ;
$output .= "<tr>\n" ;
$output .= "<td>\n" ;
$data = $database -> get_data_from_to ( $tablename , $stat , $end );
for( $i = 0 ; $i < count ( $data ); $i ++){
$output .= "<tr>\n" ;
for( $ii = 0 ; $ii < count ( $data [ $i ]); $ii ++){
$output .= "<td>" . $data [ $i ][ $ii ] . "</td>\n" ;
}
$output .= "</tr>\n" ;
}
$output .= "</table>\n" ;
echo( $output );
header ( 'Content-Type: application/vnd.ms-excel' );
header ( "Content-Disposition: attachment;filename=" . date ( "U" ). "_simple.xls" );
header ( 'Cache-Control: max-age=0' );
$objWriter = PHPExcel_IOFactory :: createWriter ( $objPHPExcel , 'Excel5' );
//$objWriter->save('php://output');
exit;
?>
Sorry to hear you're having a problem, but it might help to tell us what the problem is.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in
Nation
eBookworm.us
I'm going to guess (as you haven't actually asked a question yet ), but I think it's because you're echo'ing $output before your headers.
BTW
PHP errors will appear in your excel spreadsheet even though they are corrupt or whatever.
OPen them in notepad++ say
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks