gpt4 book ai didi

javascript - 将 html 表导出到 excel 时出错

转载 作者:行者123 更新时间:2023-11-29 19:57:40 26 4
gpt4 key购买 nike

我在将 html 表格导出到 excel 时遇到以下错误;SCRIPT429:自动化服务器无法创建对象...此功能运行良好,但当我重新启动我的电脑和应用程序时,它停止工作,不确定发生了什么。

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;
}

最佳答案

Automation server can't create object.

表示您的 ActiveX 设置太高,因此代码无法运行。

关于javascript - 将 html 表导出到 excel 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15690530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com