1

我使用此代码通过 ActiveX 复制和粘贴将 HTML 中的表格导出到 Excel。

我需要将 B 列中的所有内容设置为文本格式,因为在导出 excel 时将 0 中的内容作为第一个字符剪掉 0。我objWorksheet.Range("B:B").NumberFormat = "@"; 在行前尝试了 IobjWorksheet.columns.autofit;但它不起作用 00001 显示为 1

var wshShell = new ActiveXObject("WScript.Shell");
var userProfile = wshShell.ExpandEnvironmentStrings("%USERPROFILE%\\Desktop\\xx.xls");
var thisTable = document.getElementById("mytable").innerHTML;
window.clipboardData.setData("Text", thisTable);
var objExcel = new ActiveXObject ("Excel.Application");
//objExcel.visible = true;
var objWorkbook = objExcel.Workbooks.Add();
objWorkSheet = objWorkbook.WorkSheets(2);
objWorkSheet.Select;
objWorkSheet.Delete;
objWorkSheet = objWorkbook.WorkSheets(2);
objWorkSheet.Select;
objWorkSheet.Delete;
var objWorksheet = objWorkbook.Worksheets(1);
objWorkbook.Worksheets(1).Activate;
objWorksheet.name = "xxxxx";
objWorksheet.Paste;
objWorksheet.columns.autofit;
4

1 回答 1

0

objWorksheet.Range("B:B").NumberFormat = "00000"; 在行前添加了答案objWorksheet.columns.autofit;

于 2012-08-10T11:08:29.940 回答