The following code will let you create a template that spits out an Excel file.
I’ve kept it pretty simple, you may want to change the ordering of the fields etc.
The first part uses PHP to set the header information so you will need to enable PHP for this particular template. You’ll also probably want to set it so only store administrators can see it.
I guess if you used something like PHPExcel you could make the document much better, perhaps include charts etc.
I’m currently working on some “Store Reports” templates and plan to make use of Google charts etc. As I manage to get each bit done I’ll post them in here.
Thanks for that Pete, I’ve just used it in a completely different site, it saved me a load of work in generating some essentially useless report screens.
Now I can just set some parameters like start and end dates and pump out the data in to excel which is what the client uses anyway.
One tip I just discovered, using the following line in the header:
header(“Content-type: application/octet-stream”);
my mac doesn’t recognise the document type in order to suggest an application to open it with, so I have to download, then open in excel
by changing it to the following
header(“Content-type: application/vnd.ms-excel”);
(beware the smart quotes if copying this)
I now get the option to open the document directly in Excel.
I don’t know if there’s an even better way that will make it recogniseable as something that could be opened in openoffice also, but I’ll post that if I find it.
Pete - this order report is really useful - thanks so much.
I implemented it, and also changed the header, per shinemktg’s suggestion, to have it work as an excel doc.
But I think I’m missing something obvious - I created it as a template in EE, and so can see the report as a rendered template. But how do you then take that rendered template, and turn it into a downloadable form, that can then be opened in excel?
I tried just copying the content from the browser and pasting into excel, but the table formatting was lost, for obvious reasons….
This is brilliant. I’ve been asked about this from a few clients who want to use Cart Throb, but because i don’t have great PHP knowledge (im more front end) it’s pretty difficult for me to achieve stuff like this. Definetely going to be giving this a bash this week.
How easy would it be to make this dynamic? By having a page which allows you to choose/enter a date range, and it outputs the results as the excel? I’ve found out from a few shop owners / distributers that having this sort of feature on a shopping cms, is helpful to keep track of their income/profit.
This is a great solution…except that I can’t get it to work…
I have allowed PHP on both input or output but when I go to the template in the browser, the file I get is named orders.xls.html and doesn’t pull in the order information. It seems to place EE code in the cells.
Any thoughts?
Thanks.
Thanks for that suggestion. I should have thought of that. But in fact, it doesn’t work without the php either and I can’t, for the life of me, see why! It’s weird, I can retrieve the order number and date and a few other fields but many of the fields come in as EE tags like {order_customer_name} and then some following will retrieve correctly. I can’t see the problem even without the php code in there. Here’s the code I used, maybe on of you kind people can see my mistake. Thanks.