Your account is limited to posting only in the Pre-Sales Questions forum.
Support forum access is limited to members with a purchase history.

If you are working on behalf of another member, please contact us with the name of the license holder and we will upgrade your account.
   
2 of 2
2
How to create an Excel file template
Posted: 04 February 2011 01:30 PM   [ Ignore ]   [ # 16 ]
Wallflower
Rank
Total Posts:  9
Joined  2010-06-29

Okay, I assumed that I did and guess what? I didn’t. I forgot that a long time ago these were changed. Shoot me now! I am sorry to gunk up your thread here.
But the original problem holds, the table works for the fields that are properly mapped ( smile  ) but when I add the PHP code, the file that is downloaded is an html formatted file called orders.xsl.html. That’s the real problem at this point.
I need to go out for a bit but when I return, I’ll properly map all my fields to this in case that is the real culprit. Then I’ll reply.
Thanks

Profile
 
 
Posted: 04 February 2011 02:01 PM   [ Ignore ]   [ # 17 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29
    header("Content-Disposition: attachment; filename=orders.xls");
header(“Content-typeapplication/vnd.ms-excel”); 

Make sure you have those lines set correctly above.they control the file name and type.  Set PHP on output. Make sure that there are no characters of any kind before the open php tag.

[ Edited: 04 February 2011 02:04 PM by Chris Newton ]
 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile
 
 
Posted: 04 February 2011 05:18 PM   [ Ignore ]   [ # 18 ]
Wallflower
Rank
Total Posts:  9
Joined  2010-06-29

Thanks, I just did that but it’s still outputting an html file. I haven’t had time to remap the fields in case that’s creates the filetype problem but I don’t this it is. I’ll report once I finish. I’ll probably truncate the table just to make all the fields correct.

Profile
 
 
Posted: 04 February 2011 11:39 PM   [ Ignore ]   [ # 19 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29

How are you accessing the xl file? Do you have a link to your template page, or are you trying to view the template file directly?

 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile
 
 
Posted: 01 April 2011 12:13 PM   [ Ignore ]   [ # 20 ]
Cleans up Nice!
Avatar
RankRank
Total Posts:  370
Joined  2010-02-09

Very nice Pete… just used this myself to generate some reports for a client… worked like a charm!

Profile
 
 
Posted: 15 April 2011 04:38 AM   [ Ignore ]   [ # 21 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29

Add

<?php exit; ?> 

At the end of the template, otherwise EE will override the filename and tack on .html or whatever. Putting in exit; will allow the file to download without EE trying to add an extension for you.

[ Edited: 15 April 2011 04:57 PM by Chris Newton ]
 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile
 
 
Posted: 16 April 2011 05:21 PM   [ Ignore ]   [ # 22 ]
Wallflower
Rank
Total Posts:  9
Joined  2010-06-29

I had to drop this in February for other reasons and then I saw the last comment today and hoped it would solve the problem I mentioned where the file actually does download but in html form. It does not solve the problem sadly and now I need to work on this again. So, if anyone has any ideas, I’d appreciate it.
Thanks,
Carole

Profile
 
 
Posted: 18 April 2011 05:23 PM   [ Ignore ]   [ # 23 ]
Is a Really Great Dancer
RankRank
Total Posts:  80
Joined  2010-06-22
ccarter - 16 April 2011 05:21 PM

I had to drop this in February for other reasons and then I saw the last comment today and hoped it would solve the problem I mentioned where the file actually does download but in html form. It does not solve the problem sadly and now I need to work on this again. So, if anyone has any ideas, I’d appreciate it.
Thanks,
Carole

Hi Carole,

Are you by any chance using Safari?

Safari adds html while Firefox doesn’t. I don’t use IE so I’m not sure what it does.

Rick

Profile
 
 
Posted: 20 April 2011 11:48 PM   [ Ignore ]   [ # 24 ]
Wallflower
Rank
Total Posts:  9
Joined  2010-06-29

Rick,
Thanks for suggesting to try another browser. I was, in fact, using Safari but at your suggestion I tried both Firefox and Chrome. It didn’t work with them either. And it’s not just that there’s a .html extension, it’s actually an html file that gets downloaded. That may have not been clear. So, I get a file that has.xls ending but it’s not a spreadsheet, it’s an html file.
I hope I am more clear. Sorry for the confusion. Maybe that will help you think of what I might be doing wrong here.
Again, many thanks for any help.
Carole

Profile
 
 
Posted: 21 April 2011 01:59 AM   [ Ignore ]   [ # 25 ]
Is a Really Great Dancer
RankRank
Total Posts:  80
Joined  2010-06-22

HI Carole,

I used the table method as shown in the first example. With either the XLS or HTML extension, it opens fine as a spreadsheet in Excel. When I opened in Numbers, it didn’t import correctly.

So, a few questions:

* which spreadsheet program are you using?

* are you using a table for the output as shown in the first example?

If you want a CSV file, you might want to check out: csvEE http://expressionengine.com/archived_forums/viewthread/42155

==

I’ve attached the xls.html file that my system outputs. (The one that opens fine in Excel, but not in Numbers)

rick

File Attachments
cartthrob-2277.xls.html  (File Size: 2KB - Downloads: 68)
Profile
 
 
Posted: 21 April 2011 09:33 PM   [ Ignore ]   [ # 26 ]
Wallflower
Rank
Total Posts:  9
Joined  2010-06-29

Ah! You’re killing me! You’re right, i am trying to access it in Numbers. I’ll be able to test your theory out tomorrow. Thanks for checking that out and I’ll confirm if it’s a Numbers vs. Excel issue.
Seriously, thanks. I would not have thought that it was a problem for that reason. I’ll respond tomorrow and confirm one way or another.
Carole

Profile
 
 
Posted: 27 April 2011 07:43 AM   [ Ignore ]   [ # 27 ]
Has a Nice Profile
Avatar
RankRank
Total Posts:  127
Joined  2010-05-24

I posted a while back asking if it would be easy enough to create a form where the client can choose a date range, and download sales reports etc. I’ve finally got round to doing it, and thought i would share the code on here:

Place this in an EE template. Please note i’ve used the Loop plugin to make it auto generate the dates / years. You will also need to change the URL in the ‘action’ parameter to point to your ‘download’ template.

<form method="post" action="http://www.website.com/index.php/reports/download">

<
div style="border: 3px solid #F2F2F2; padding: 10px; margin: 10px;">

<
strong>Start Date</strong><br><br>

<
select name="start-day">
{exp:for_loop start="01" end="31" increment="1"}  
  
<option value="{index}">{index}</option>
{/exp:for_loop}
</select>

<
select name="start-month">
    <
option value="01">January</option>
    <
option value="02">February</option>
    <
option value="03">March</option>
    <
option value="04">April</option>
    <
option value="05">May</option>
    <
option value="06">June</option>
    <
option value="07">July</option>
    <
option value="08">August</option>
    <
option value="09">September</option>
    <
option value="10">October</option>
    <
option value="11">November</option>
    <
option value="12">December</option>
</
select>

<
select name="start-year">
{exp:for_loop start="2008" end="2015" increment="1"}  
  
<option value="{index}" {if {loop_count} == 4}selected{/if}>{index}</option>
{/exp:for_loop}
</select>


</
div>

<
div style="border: 3px solid #F2F2F2; padding: 10px; margin: 10px;">

<
strong>End Date</strong><br><br>

<
select name="end-day">
{exp:for_loop start="01" end="31" increment="1"}  
  
<option value="{index}">{index}</option>
{/exp:for_loop}
</select>

<
select name="end-month">
    <
option value="01">January</option>
    <
option value="02">February</option>
    <
option value="03">March</option>
    <
option value="04">April</option>
    <
option value="05">May</option>
    <
option value="06">June</option>
    <
option value="07">July</option>
    <
option value="08">August</option>
    <
option value="09">September</option>
    <
option value="10">October</option>
    <
option value="11">November</option>
    <
option value="12">December</option>
</
select>

<
select name="end-year">
{exp:for_loop start="2008" end="2015" increment="1"}  
  
<option value="{index}" {if {loop_count} == 4}selected{/if}>{index}</option>
{/exp:for_loop}
</select>

</
div>

<
div style="border: 3px solid aqua; padding: 10px; margin: 10px;">
<
input type="submit" name="submit" value="Download" /> 
</
div>

</
form

Then place the code below in a template named “download” or something similar. Enabling PHP and set the parsing to input. Please note i haven’t added the Excel code below, but its easy enough to add between the weblog tags.

<?php

$start_date 
$_POST['start-year'].'-'.$_POST['start-month'].'-'.$_POST['start-day'];
$end_date $_POST['end-year'].'-'.$_POST['end-month'].'-'.$_POST['end-day'];

?> 

{exp
:weblog:entries weblog="orders" orderby="date" limit="400" start_on="<?php echo $start_date; ?> 00:00" stop_before="<?php echo $end_date; ?> 23:59"}
{title} 
- ( {entry_date format="%Y %m %d")<br />
{/exp:weblog:entries}

----
<
br>
Start <?php echo $start_date?>
<br>
End <?php echo $end_date?>
<br>
---- 

I’ve placed a bit of code at the bottom of that template so you can see if the PHP is outputting.

smile

Profile
 
 
Posted: 29 July 2011 06:42 AM   [ Ignore ]   [ # 28 ]
Is a Really Great Dancer
RankRank
Total Posts:  73
Joined  2010-05-07

Scratch this - I’ve gone about this using CSVEE - seperate question here:
http://cartthrob.com/forums/viewthread/3187/


—-

I have this code working to produce a download, but I need to produce a file which can be imported into Metapack for a customer’s order fulfillment - “it needs to be delimited so it is in a database format” is the response I got.

Can anyone suggest how I should edit the php / formatting to do this?

Code is below…

cheers
Kevin

<?php
header
("Content-Disposition: attachment; filename=orders.csv");
header("Content-type: application/vnd.ms-excel");  
header("Pragma: no-cache");
header("Expires: 0");
?>
<table border="1">
  <
tr>
        <
th>Order No.</th>
        <
th>Date</th>
        <
th>Customer name</th>
        <
th>Customer email</th>
        <
th>Customer phone</th>
        <
th>Items</th>
        <
th>Total</th>
        <
th>Billing address</th>
        <
th>Shipping address</th>
        <
th>Status</th>
        <
th>Transaction ID</th>
  </
tr>
{exp:weblog:entries weblog="ordered_items" orderby="entry_id" sort="desc" limit="500"}
    
<tr>
    <
td>{title}</td>
    <
td>{entry_date format="%d.%m.%Y"}</td>
    <
td>{order_shipping_first_name} {order_shipping_last_name}</td>
    <
td>{order_customer_email}</td>
    <
td>{order_customer_phone}</td>
    <
td>
        
{order_items}
        {item
:quantity} x {item:title} {item:price} each<br />
        
{/order_items}
    
</td>
    <
td>{order_total}</td>
    <
td>{order_billing_address}<br />{order_billing_address2}<br />{order_billing_city}<br />{order_billing_state}<br />{order_billing_zip}<br />{order_billing_country}</td>
    <
td>{order_shipping_address}<br />{order_shipping_address2}<br />{order_shipping_city}<br />{order_shipping_state}<br />{order_shipping_zip}<br />{order_shipping_country}</td>
    <
td>{status}</td>
    <
td>{order_transaction_id}</td>
    </
tr>
{/exp:weblog:entries}
</table>
<?php exit; ?> 
[ Edited: 29 July 2011 09:37 AM by Kevin ]
Profile
 
 
   
2 of 2
2
 
‹‹ Sample Email Templates      Ajax Add to Cart ››