2

Im getting the following error while exporting an html table to excel; SCRIPT429: Automation server can't create object... This function was working fine but when i restarted my pc and the the application it stopped working not sure whats going on.

function write_to_excel() {
str = "";
var myTable = document.getElementById('myTable');
var rows = myTable.getElementsByTagName('tr');
var rowCount = myTable.rows.length;
var colCount = myTable.getElementsByTagName("tr")[0]
        .getElementsByTagName("th").length;

var ExcelApp = new ActiveXObject("Excel.Application"); //Debug shows error at this  line
var ExcelWorkbook = ExcelApp.Workbooks.Add();
var ExcelSheet = ExcelWorkbook.ActiveSheet;

ExcelApp.Visible = true;
ExcelSheet.Range("A1", "Z1").Font.Bold = true;
ExcelSheet.Range("A1", "Z1").Font.ColorIndex = 23;

// Format table headers
for ( var i = 0; i < 1; i++) {
    for ( var j = 0; j < colCount - 1; j++) {
        str = myTable.getElementsByTagName("tr")[i]
                .getElementsByTagName("th")[j].innerHTML;
        ExcelSheet.Cells(i + 1, j + 1).Value = str;
    }
    ExcelSheet.Range("A1", "Z1").EntireColumn.AutoFit();
}
for ( var i = 1; i < rowCount; i++) {
    for ( var k = 0; k < colCount - 1; k++) {
        str = rows[i].getElementsByTagName('td')[k].innerHTML;
    ExcelSheet.Cells(i + 1, k + 1).Value =  myTable.rows[i].cells[k].innerText;
    }
    ExcelSheet.Range("A" + i, "Z" + i).WrapText = true;
    ExcelSheet.Range("A" + 1, "Z" + i).EntireColumn.AutoFit();
}

return;
  }

1 Answer 1

3

Automation server can't create object.

Means your ActiveX settings are too high so the code will not run.

Sign up to request clarification or add additional context in comments.

5 Comments

Is there a way to get around this problem without changing the setting i would to tell all the user to fix the ActiveX setting. I just need export to excel function that works on IE
@Teemu Thanks for your comment what I meant was is there another way to export a table to excel that doesn't require ActiveeXObject. Ive tried couple other codes without ActiveXObject but they only work in chrome and firefox. So far all I'm finding is with ActiveXobject for IE.
Send the data to the server and have your server make the file and return it to the client.
@epascarello , can you elaborate on what you mean by "...have your server make the file and return it..." as I have the same issue as above. The code I am working with is classic ASP and bloated beyond imagination, so a research starting point link would be helpful.
@JoshCampbell Post a form to the server and with ASP it would be something like Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls". There are plenty of exaples on generating the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.