1

Hello I am creating a Excel file with PHP. I am setting the header, before I print out some data:

header('Content-type: application/vnd.ms-excel; charset=utf-8');

And then I am inserting something like:

echo '<table><tr><td>täääst</td></tr></table>';

My problem is that the ä isn't shown right in the excel file.

I am also having an error, when I open the file that says:

The file you are trying to open, 'filename.xls', 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?

Can you help me please? Thank you in advance.

3
  • You're not creating an Excel file, you're writing HTML markup and telling the browser to treat it as an .xls file.... that's not the same; and the content-type charset is meaningless.... If you want to keep on working with the HTML Markup as tthough it were an Excel file, you'll need to set the charset in the html head block Commented Jan 28, 2013 at 14:30
  • And because HTML !== XLS, you'll get this different format error unless you change your approach and write a real XLS file using one of the many PHP libraries written specifically for that purpose Commented Jan 28, 2013 at 14:31
  • If your purpose is simple, then you could also simply create a CSV file which is compatible with Excel as well. Commented Jan 28, 2013 at 14:31

1 Answer 1

4

You're not creating an excel file. You're creating an HTML file and telling excel to pretend it's an .xls. That's why you're getting the "different format" warning.

Use PHPExcel to create a native excel file (.xls or .xlsx).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.