
Create excel file with Miva Script
Written by Claudiu Bischoff, on 3 april 2009
OVERVIEW
I always heard that creating Excel files on the fly is very hard to do it on Linux servers. But what about creating those files on Linux with 100% pure Miva Script :) It's not the most elegant way to do it, but it works :)
All we have to do, is to override the header of the page and change the content-type to "application/vnd.ms-excel".
Tip: Don't forget to add '<miva standardoutputlevel="compresswhitespace">' on top of your file, as Miva Script can add unwanted characters to your content and the downloaded file will be corrupted.
COMPATIBILITY
You must use Miva Empresa 4+ (the miva_output_header and file_read functions aren't available in lower versions of Empresa)
THE CODE
You can see the code here: http://mivascript.org/share/scripts/force_download_excel.mv.txt
How to call the function :
<miva standardoutputlevel="compresswhitespace">
<MvCOMMENT>
Variables:
l.filename - The name of the file (it is shown when the download pops up)
l.content - The "tabled" content you will show on the spreadsheet
</MvCOMMENT>
<mvassign name="l.filename" value="{'test.xls'}">
<mvassign name="l.content" value="{'<table border="1">
<tr>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
</tr>
<tr>
<td>Some first name</td>
<td>Some last name</td>
</tr>
</table>'}">
<mvassign name="l.content" value="{Generate_Header(l.filename, l.content)}">
<MvIF EXPR="{ l.content:error }">
<MvEVAL EXPR="{l.content:error}"><MvEXIT>
<MvElse>
<MvEVAL EXPR="{l.content}">
</MvIF>
DEMO
Direct download of this spreadsheet:
click here
TODO
Nothing for the moment :-)
COMMENTS
I started a thread in the Miva Merchant (Miva Script section), so don't hesitate: http://extranet.mivamerchant.com/forums/showthread.php?t=20577

