:: Forum >>

Client side Grid Export To Excel

function ToExcel(){


if (window.ActiveXObject){

var xlApp = new ActiveXObject("Excel.Application");
var xlBook = xlApp.Workbooks.Add();


xlBook.worksheets("Sheet1").activate;
var XlSheet = xlBook.activeSheet;
xlApp.visible = true;

for(var P = 1; P<= obj.getRowProperty("count"); P++){

for(var Q = 1; Q <= obj.getColumnProperty("count"); Q++){
if (P==1){
XlSheet.cells(P ,Q).value = obj.getColumnProperty("text",Q-1)
}

XlSheet.cells(P +1,Q).value = obj.getDataText(P-1,Q-1);
}
}
XlSheet.columns.autofit;
}
}//end function
Leon Van Zyl
Friday, July 15, 2005
Hi Leon Van Zyl,
I am using the script above "ToExcel()" function to export to excel. Its working fine when i use it locally (WITHOUT PUTTING IN MY TOMCAT SERVER). But when I upload the file on Tomcat server and use it there. It doesn't allow me. It says "Automation server cannot create object". I know that the active x object is not being created. but i dont know how to enable it.

Please contact me immediately as I am in need.

Reply to m4manoj@gmail.com

Thanks,
- Manoj.
Manoj
Monday, September 12, 2005
Hi Leon Van Zyl,
thanks for the code, It works wonderful with IE. How this code can be modified to work in firefox under windows?


Thanks in Advance,
Kumar S
Kumar S
Tuesday, September 13, 2005
it can't work in firefox
Friday, September 16, 2005
I am facing the same problem detailed above e.g. "Automation server cannot create object". I know that the active x object is not being created. but i dont know how to enable it
Is there anyone who know how to enable it

Love to see response very soon
ali
Friday, November 25, 2005
This is Client side automation, should thus be run within client side script..
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757
leon
Monday, November 28, 2005
Hi Ali,

To enable it .. use the below procedure:

Go to
Tools -> Internet Options -> Security -> Custom Level

Select Prompt in Download signed ActiveX controls.

When prompted select Yes and you will be able to create the ActiveX object.

Manoj
Friday, December 2, 2005
Hello -

Has anyone tried this script in v2.?

When doing so it seems to be bombong out at:

XlSheet.cells(P ,Q).value = obj.getColumnProperty("text",Q-1)

Any thoughts??
tricki
Friday, February 10, 2006
This solution requires Automation Objects in client side, that FORCES the client side to have Automation Object (by meas of M$ Office setup) and completelly disscard a general solution.

Consider XML and excel file generation by XSL transformations. This is a little bit complicated but pretty flexible.

Regards...
Raciel R.L.
Friday, February 10, 2006
How do i get this to work with Version 2?
Lasse
Wednesday, March 15, 2006
HI raciel, please tell me more about the solution u propose about the XLS transformation.. where can i find a code example ??
Dave
Wednesday, March 29, 2006
Hi,



I am Kapil Gupta and presently working on exporting data to Microsoft Excel. Basically I am creating ActivXObject for it.



<html>

<head>

<script type="text/javascript">



function writeme()

{

var excel = new ActiveXObject ("Excel.Application");

excel.visible = true;

var book = excel.Workbooks.Add ();

var sheet = excel.Worksheets(1);



sheet.Range ("A1") = "Checking";

sheet.Pictures.Add(5,6,"C:\\me.gif");



}

</script>

</head>

<body onload="writeme()">

</body>

</html>





On loading it is giving “Error:Argument not Optional”.



I have searched a lot for it on net but coud not find any fruitful results in javascript.

Can u please help me with this

Monday, June 5, 2006
can u give me the same fix which can work with both mozilla and IE.

please, It's immediate requirement
mustu
Thursday, August 3, 2006
can u give me the same fix which can work with both mozilla and IE.

please, It's immediate requirement
mustu
Friday, August 4, 2006
The code posted by Leon Van Zyl worked great. However, quotes "" get encoded in Excel and appear as &quot; How can that be avoided?
Peter G.
Monday, August 28, 2006
Update for v2, still doesn't work in FF:

function ToExcel(){
if (window.ActiveXObject){
var xlApp = new ActiveXObject("Excel.Application");
var xlBook = xlApp.Workbooks.Add();

xlBook.worksheets("Sheet1").activate;
var XlSheet = xlBook.activeSheet;
xlApp.visible = true;

var xlRow = 1;
var xlCol = 1;

for (var C = 0; C < table.getColumnCount(); C++){
XlSheet.cells(xlRow, xlCol).value = table.getHeaderText(table.getColumnIndices()[C]);
xlCol++;
}

for (var R = 0; R < table.getRowCount(); R++) {
xlRow++;
xlCol = 1;
for (var C = 0; C < table.getColumnCount(); C++) {
XlSheet.cells(xlRow, xlCol).value = table.getCellText(table.getColumnIndices()[C], R);
xlCol++;
}
}
XlSheet.columns.autofit;
}
}
Mike
Tuesday, September 5, 2006
Hi Leon Van Zyl, Manoj

I have script, which is used to export the table information to the excel file.
The code is working fine in client machine (I am using Windows XP & IE 6.0). I have uploaded the same file in free hosting server, and tested the same html page using IE 6.0, but its not downloading(not open the excel file with data).

What's the issue in that? Could please help me to resolve this?

My code is given below:
<html>
<head>
<title>Testing</title>
</head>
<body>
<script language="vbscript">
Sub exporttoexcel
Dim sHTML
Dim oExcel
Dim oBook
sHTML = document.all.item("inner_table").outerhtml
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oExcel.Visible = true
oExcel.UserControl = true
End Sub
</script>
<table border = 0 cell padding = 0>
<tr>
<td><font size = -1><a href='javascript:exporttoexcel()'>Export To Excel</a></td>
</tr>
</table>

<table id ="inner_table">
<tr><td> Hello</td></tr>
</table>
</body>
</html>

Thanks
skumar
Tuesday, March 27, 2007
how to convert jsp page to excel Sheet
plz try to help me it's very urgent
RK
Wednesday, July 25, 2007

This topic is archived.


Back to support forum

Forum search