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
Richard KortsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Julian HansenConnect With a Mentor Commented:
Ok before we deal with the rewrite - I am confused because the file you posted opens for me - are you saying that that same file does not open for you (or your clients)?

The XML Excel format.

Basically what I would do is save one of your existing files as a .XML file (Using the Save As .XML in Excel).

You can then edit the file and chop out the header bits - the bits that don't change - and paste these as the header and footer bits in your code.
You can then look at how the rows are generated and just adapt your HTML table code to output the equivalent XML code - the methodology is exactly the same - only slightly different markup.
If you get stuck post back and I will demonstrate.

First up though I am interested to know if the file you posted earlier works or fails - and if it fails how does it fail - as I mentioned before it opens fine for me.
0
 
Julian HansenCommented:
Can you post the downloaded file.
0
 
Richard KortsAuthor Commented:
Download File attached.
usage2016-08-01_03_41.xls
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Ray PaseurConnect With a Mentor Commented:
It looks like this programming does not create an XLS spreadsheet.  Instead it appears to create an HTML document.  Is is possible for you to create the SSCCE, using a smaller test case so that you can isolate the failure?  If we can see the isolated failure we might have a better chance of offering a suggestion to fix it!
0
 
Richard KortsAuthor Commented:
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
0
 
Ray PaseurCommented:
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.
0
 
Richard KortsAuthor Commented:
Ray,

I will generate a smaller file.

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

Thanks,

Richard
0
 
Richard KortsAuthor Commented:
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
0
 
Julian HansenCommented:
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.
0
 
Richard KortsAuthor Commented:
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
0
 
Richard KortsAuthor Commented:
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
0
 
Julian HansenCommented:
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.
0
 
Richard KortsAuthor Commented:
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
0
 
Richard KortsAuthor Commented:
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
0
 
Richard KortsAuthor Commented:
Julian,

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

That works. But so what?

My customers use Microsoft Excel.
0
 
Julian HansenCommented:
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.
0
 
Richard KortsAuthor Commented:
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
0
 
Richard KortsAuthor Commented:
No solution, points awarded based on effort.
0
 
Julian HansenCommented:
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.
0
All Courses

From novice to tech pro — start learning today.