Click to See Complete Forum and Search --> : Script that converts HTML/Freemarker table to Excel


jwoodall01
May 8th, 2008, 02:10 PM
I have an html/freemarker table that I need to be able to convert to excel with the click of a button. This is the closest I have been able to get to having it work: (simplified example)

File: untitled.ftl

<#include "/include/html.ftl"/>
<html>

<Script Language="VBScript">
Sub RunScript
strCopy = MyTable.InnerHTML
document.parentwindow.clipboardData.SetData "text", strCopy

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Paste
End Sub
</Script>

<body>

<span id=MyTable>

<table border=1>
<tr bgcolor="ECEBEB">
<td colspan=5><center><#if params.state.value=="">All States<#else>${params.state.value}</#if></center></td>
</tr>
<tr>
<td colspan=5><center><#if params.product.value=="">All Products<#else>${params.product.value}</#if></center></td>
</tr>
<tr bgcolor="ECEBEB">
<td colspan=5><center>Sales and Distribution</center></td>
</tr>
</table>

</span>

<input id=runbutton type="button" value="Export to Excel" onClick="RunScript">

</body>
</html>

This gives me an error saying "Object doesn't support this property or method" when I click on the button.

PeejAvery
May 8th, 2008, 03:31 PM
Well, I don't work with Freemarker, but the copy and pasting of the table works perfectly on my PC at work.

jwoodall01
May 8th, 2008, 04:03 PM
Well, a copy and paste from the browser does work... I'm looking for a convenient (idiot) way to let someone do it with the click of a button.

PeejAvery
May 8th, 2008, 04:57 PM
That's what I was trying to tell you. I clicked the button, Excel opened, and it pasted right in. No problem whatsoever.

Just note that since you are using VBScript, you are restricting yourself to Internet Explorer. But, I'm sure you already knew that.