ActiveX - Not working on IIS Server

Discussion in 'JavaScript' started by koolsamule, Jan 6, 2010.

  1. #1
    Hi Chaps,
    I have JavaScript code, that exports a HTML table to MS Excel.
    This works fine on my development (local) server, however, it fails to work on my 'live' IIS server. Once I click on the Export link, I confirm the "Export to Microsoft Excel?" message, then nothing happens. I am not sure if MS Excel needs to be installed on the server or not?
    If anyone has any ideas, I'd be most grateful:
    <script language="javascript" type="text/javascript">  
    function ExportToExcel() {
    	input_box=confirm("Export to Microsoft Excel?");
    		if (input_box==true) {
    			
    			var xlApp = new ActiveXObject("Excel.Application");
    			// Silent-mode:
    			xlApp.Visible = true;
    			xlApp.DisplayAlerts = false;
    			var xlBook = xlApp.Workbooks.Add();
    			xlBook.worksheets("Sheet1").activate;
    			var XlSheet = xlBook.activeSheet;
    			XlSheet.Name="Report";
    			
    			// Store the sheet header names in an array
    			var rows = tblrepeat.getElementsByTagName("tr");
    			var columns = tblrepeat.getElementsByTagName("th");
    			var data = tblrepeat.getElementsByTagName("td");
    			
      			// Set Excel Column Headers and formatting from array
    			for(i=0;i<columns.length;i++){
    				XlSheet.cells(2).value= "Projects - All";
    	   			XlSheet.cells(3,i+1).value= columns[i].innerText; //XlSheetHeader[i];
    	   			XlSheet.cells(3,i+1).font.color="6";
    	   			XlSheet.cells(3,i+1).font.bold="true";
    	   			XlSheet.cells(3,i+1).interior.colorindex="37";
    				XlSheet.Range("A1:B1000").HorizontalAlignment = -4131;
    			}
    			
    			//run over the dynamic result table and pull out the values and insert into corresponding Excel cells
    			var d = 0;
    			for (r=4;r<rows.length+3;r++) { // start at row 2 as we've added in headers - so also add in another row!
    				for (c=1;c<columns.length+1;c++) {
    					XlSheet.cells(r,c).value = data[d].innerText;
    					d = d + 1;
    				}
    			}
    			
    			//autofit the columns
    			XlSheet.columns.autofit;
    			
    			// Make visible:
    			xlApp.visible = true;
    			xlApp.DisplayAlerts = true;
    			CollectGarbage();
    			//xlApp.Quit();
    		}
    }
    </script>
    Code (markup):

     
    koolsamule, Jan 6, 2010 IP