/    Sign up×
Community /Pin to ProfileBookmark

I am having a small problem publishing to excel

[code=php]
<?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;
?>

[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 06.2012 — Sorry to hear you're having a problem, but it might help to tell us what the problem is. ?
Copy linkTweet thisAlerts:
@Alan01252May 07.2012 — 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.
Copy linkTweet thisAlerts:
@BelrickMay 09.2012 — BTW

PHP errors will appear in your excel spreadsheet even though they are corrupt or whatever.

OPen them in notepad++ say
×

Success!

Help @moiseszaragoza spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...