/    Sign up×
Community /Pin to ProfileBookmark

PHP Excel header problem

Okay, I’m generating a table that I want to export to excel. I’ve tried exporting the table in text-tab delimited, basic table (no class/id affixed), and the table as generated naturally (with css class and id parameters). Every time I try this, I receive the following error:

[code]
The file you are trying to open {FILENAME} is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
[/code]

The file opens and the data is there and formatted correctly. I’m trying to get rid of the error.

I’m pretty sure that I’m either getting this error because I’ve set the headers wrong, or I’m somehow screwing up the table, but I haven’t found anything on the web that seems to point to how to do it correctly. People just stop responding after folks ask how the table is generated.

So here are the headers:

[code=php]
header(“Content-type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=excelfile.xls”);
echo $formatter->formatReport( “”, $_GET[ ‘report’]);
[/code]

I’ve also tried content type octet-stream, and application/ms-excel with the html w/class&id, but not with the other two permutations. Both tries to no avail.

The table that gets output can be in any of the formats specified above (text-tab, no parameter table, table with class/id tags). If the new version of excel finally solidified a format, could someone link a document that shows the right way to do it?

Thanks in advance.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@janusmccarthyauthorJun 14.2010 — Solved my own question:

The alert is a new feature in office 2007 called Extension Hardening and is done by design. There are ways to turn off the warning message by editing the registry, but the only way to pass through the Extension Hardening check unscathed is to write the export file in BIFF8 format.

http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx

There's a small workaround here if you're interested in writing around the solution using php:

http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8

The full solution would probably be to use something like the spreadsheet writer available through pear or something like PHPExcel
×

Success!

Help @janusmccarthy 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,
)...