Export weblog as a text file
published on Mar 01st, 2006 // 8 Comments
Have you ever wanted to download all your weblog entries as a text file. Well now you can with some this simple tutorial.
Lets start by assuming that you have an Expression Engine website. It would ideally suit a site with a product catalog. You may have a weblog called products. You require this as in Excel format so you can mail to different retailers. We will work with this pretense till the end of the tutorial where by then you should have learned enough to adapt it to your own needs.
We begin by making a new template called excel_products in your Product template group.
In this template we are going to call all our product info.
PRODUCTNAME|PRODUCTID|COLOUR|PRICE{exp:weblog:entries weblog="products" orderby="product_price" limit="500" }{title}|{product_id}|{product_colour}|{product_price}{/exp:weblog:entries}
To examine the above template. The first line are the fields that will be generated as headings for our excel sheet.
In the weblog tag we are calling our products weblog and ordering by our custom field product_price and setting a limit to 500 to start with. You can also see the other custom fields I used for my products. things to note – Excel headings must match in number the amount of fields you are using.There is a line-break after the last excel heading and after {product_price}. Save this template.
Next make another template in this group called excel_script, turning PHP on for this template.
Inside this template you will add this code and save it.
excel_script template download
What does this script do?
The first line is where we embed the template we just made so update this path.
$string = "";
The second line is the type of file we are downloading which is .txt
$ext = "txt";
Getting today’s date
$today = date("dmY");
This is where we name our file so using the code below our file will be called productlist_01032006.txt
$filename = "productlist_".$today;
What you do to link to your template is up to you. You might want to add it to your main site for frontend users or do what I have done and goto MY ACCOUNT >> Quicklinks in your Control Panel and add the link to your products/excel_script/ there.
After downloading your newly generated text file you will have to import it into Excel not as comma delimited but using | (pipe character) instead
8 Comments
Thomas Tolleson says:
Notice: Use of undefined constant PMA_USR_BROWSER_AGENT – assumed ‘PMA_USR_BROWSER_AGENT’ in PATH\system\core\core.functions.php(629) : eval()‘d code</b> on line 6
I made the suggested Changes, the result was successful.
Thomas Tolleson says:
OK, just checked the saved file and I’m seeing links for trackbacks and a bunch of dublin corp tags. Not really what I was after, but perhaps I can mod this to work properly.
Thanks again!
Thomas Tolleson says:
He he. Dublin Core, I should say.
Cem says:
Thank you for this script.
FYI, I was a also able to download as xls by changing the delimeter from “|” to “TAB”.
Adam Khan says:
Thanks for this. Am going to need it this week.
Bunker says:
Hmm… I read blogs on a similar topic, but i never visited your blog. I added it to favorites and i’ll be your constant reader. cheap cipro
Bunker says:
I added your blog to bookmarks. And i’ll read your articles more often!




Thomas Tolleson says:
This is fantastic! I need to export my weblog as a microsoft Word Document. Any advice?
I’ll try and change your export script and let you know if I have any luck.
THT