Download Miva EmpresaDownload Miva Mia
Miva Script used functions:
More informations on miva_output_header function  miva_output_header
Tags

miva output header, excel , header, content-type, Content-Transfer-Encoding, Content-Length, Content-Disposition, Cache-Control, Pragma

Other Miva Scripts

More informations on Get Image Size function   Install Miva Empresa Mysql5 on Ubuntu
More informations on Get Image Size function  Get image size with Miva Script
More informations on miva_output_header  File Tree with JQuery and Miva Script
More informations on miva_output_header   Miva_output_header and forced download
More informations on miva_output_header   Miva_output_header and excel files

Download Miva Merchant
Search
OK
OK

Create excel file with Miva Script

Written by Claudiu Bischoff, on 3 april 2009

In the latest article, I wrote about how simple was to force the download of a file by using the Miva Script function " miva_output_header ". Now, I'm going to use the same function to create Microsoft Office Excel files.


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 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

 

Miva Merchant, Miva Script, and the Miva Merchant blades logo are registered trademarks of Miva Merchant Corporation. MivaScript.org is not affiliated with Miva Merchant. Copyright © 2009 MivaScript.org - All rights reserved.
Miva Script ressources