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