Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Issue creating excel from php

See attached php.

The purpose of this program is to query a table in a MySQL database & create an excel spreadsheet of the selected info for downloading. The technique used here I have been using for many years and worked here until yesterday or VERY recently.

When this runs, it opens the window for downloading the created file; if opened in Excel, it is empty.

To debug, I removed the top 3 php lines. It runs & generates an html table with the correct data, as it should.

It is possible I MIGHT have messed up the syntax of the top 3 lines.

Can someone tell me what is wrong?

Thanks
gen_excel_real.php
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Can you post the downloaded file.
Avatar of Richard Korts

ASKER

Download File attached.
usage2016-08-01_03_41.xls
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray,

Do you mean less data or a shorter php program?

FYI, I have been using this EXACT technique for years. It works today for other clients & worked for this one as recently as July 21. To my knowledge, I made no changes since then.

The Host (Chihost) said there was a php upgrade on July 24 but it did not mention anything about this. Here is the change log.

http://php.net/ChangeLog-5.php#5.5.38

Richard
Less data.  This file has over 25,000 lines of code.  That's too much to wade through.  When I save the file with an XLS extension, it cannot be opened by Excel.

Can ChiHost give you a file extension that will run a backlevel version of PHP?  If so, you might be able to get before-and-after comparisons.  That might help isolate the changes that caused the issues.
Ray,

I will generate a smaller file.

Great point about a backlevel version; I will ask them.

Thanks,

Richard
Ray,

Terry at Chihost said this: There isn't a way to rollback to a previous "release" version.

I will generate a small output file & post it this PM.

Richard
I suspect your problem is this - based on the sample file you uploaded.

That file has the following on the first line
qry = SELECT * from cvisitor where (SUBSTRING(last_time,1,10) >= '2016-05-01' and SUBSTRING(last_time,1,10) <= '2016-08-01') and vtype = 'R' order by last_time<br><!DOCTYPE html>

Open in new window

This is being output by the following line (line 47)
echo "qry = " . $qry . "<br>";

Open in new window


After removing this from the output - Excel opens the file.
Julian,

Still does NOT work for me.

See attached.

Ray this is a small file, if not small enough, I can do just one day.
usage2016-08-02_02_11.xls
I have another customer, also hosted in the same place where I used the IDENTICAL technique to generate Excel reports.

I just ran one, it failed in the same way. In that case, the program (php file) was last changed on 12/6/2014.

I think this is where I first found the method I am using: http://webcheatsheet.com/php/create_word_excel_csv_files_with_php.php

Richard
Excel opens that file for me  - it gives a warning but if you say yes to the warning the file opens.

Is this not perhaps an issue with Excel?

Are you open to doing a minor re-write on the code? If so you might consider converting over to Excel XML format. Not too different from what you have right now so code change would be fairly small.
Julian,

Yes, when it works, it gives me that warning too.

I have another customer, also hosted in the same place where I used the IDENTICAL technique to generate Excel reports.

I just ran one, it failed in the same way. In that case, the program (php file) was last changed on 12/6/2014.

Excel works for everything else.

I am willing to try a minor re-write. Can you provide details?

Of course I can't understand why I have to change something that worked 10 days ago. I am 95% certain that the php upgrade on the host is the cause.

Richard
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Julian,

The file does NOT open for me. It does open for you & the Web Host. I download it (rather than open directly in Excel), then open in excel from the download folder.

I just a few minutes ago emailed it to the customer & asked them to open it in Excel.

I'm beginning to think it's my Excel.

Richard
Julian,

I emailed to my customer. He cannot open it either (in Excel).
As another piece of data, the host suggested I download OpenOffice & try it there.

That works. But so what?

My customers use Microsoft Excel.
So, if I understand correctly - this is something specific to the client in terms of their specific instance of Excel?

If so the question is what changed on their side. If it is not reversible then I recommend the XML route described above.
The problem is not solved.

The EXACT same technique is used on another host for a variety of reports. I asked the customer to try one, it worked fine.

A DIFFERENT customer on the same host experiences the same problem.

I am converting the method to generate a csv file.

There is no reason that has been explained to me why this worked for years & now doesn't.

I'm awarding points for this question based on level of effort.

Thanks,

Richard
No solution, points awarded based on effort.
Thanks Richard, but I believe this is something specific to Office at the client's location.

The fact that your code base has not changed and the generated files can be opened by others using Excel - it points to a problem local to the client.

I expect it has something to do with an Office update that was applied. I have turned updates off and have not updated office for some time - which might explain the issue.