How to export a files in php

That's a pretty vague question. What type of file? What is the data source?
You'll need to provide more details to get a good answer.

Usually these would be written to the file system as CSV (comma separated value) files that Excel can handle very well. I used to do that with PHP to generate cell phone performance data for Nokia's quality assurance department.

I've only had to export to Excel once for a full Excel report with multiple tabs, charts, etc. Typically, I would be exporting out to a CSV file.