Avatar of Richard Korts
Richard Korts
Flag for United States of America asked on

Generating Excel in php

I have been using this technique for years to generate Excel spreadsheets from a php program.

At the beginning of the php is this code:

<?php
header("Content-type: application/vnd.ms-excel; charset=UTF-8");
$fn = "excel" . date('Y-m-d_h_i') . ".xls";
header("Content-Disposition: attachment; filename=" . $fn);
?>

Open in new window


Then I build an old fashioned HTML table with rows & columns that become the rows & columns of the spreadsheet.

If I change the line: $fn = "excel" . date('Y-m-d_h_i') . ".xls"; to $fn = "excel" . date('Y-m-d_h_i') . ".xlsx";,
will that cause it to generate an xlsx file compatible with current Excel?

Or is there a better way?

Thanks
Microsoft ExcelPHP

Avatar of undefined
Last Comment
manuverhaegen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
manuverhaegen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
gr8gonzo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Richard Korts

ASKER
I found this: https://phpexcel.codeplex.com/ and did a test, it works great & Excel opens the output perfectly. Excel 2016 on my Windows 10 machine to be exact, to be exact.

It looks similar to manuverhaegen's but I don't know where the class Spreadsheet/Excel/Writer.php comes from.

I think I will try phpExcel.

I failed to mention in my question, I really need to save it to a file on the server, not auto download. It appears phpExcel can do either.
Richard Korts

ASKER
manuverhaegen

Can you point me to where I can get the classes you are using?

Thanks
manuverhaegen

Your help has saved me hundreds of hours of internet surfing.
fblack61