View Full Version : ActiveX - Export to Excel Question

06-22-2010, 12:53 PM
Hi Chaps,

I have some Javascript code, that sucessfully exports Project data from an HTML table to an Excel SpreadSheet:

function ExportToExcel() {
var xlApp = new ActiveXObject("Excel.Application");
// Silent-mode:
xlApp.Visible = true;
xlApp.DisplayAlerts = false;
var xlBook = xlApp.Workbooks.Add();
var XlSheet = xlBook.activeSheet;
XlSheet.Name="Project Details";

// Store the sheet header names in an array
var rows = tbldisplay.getElementsByTagName("tr");
var columns = tbldisplay.getElementsByTagName("th");
var data = tbldisplay.getElementsByTagName("td");

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

// Make visible:
xlApp.visible = true;
xlApp.DisplayAlerts = true;
As you can see, a new workbook is created and the data is exported to Excel ("Sheet1").
What I want to do is as soon as this export is complete, redirect to a seperate page, where the Jobs (linked to the Project) details are exported to Excel ("Sheet2"), without creating a new workbook.
Is this do-able?