如何从IE中通过ActiveX设置Excel列格式
我使用这个代码来导出HTML中的表格以通过ActiveX复制和粘贴来实现Excel。
我需要将B列中的全部设置为文本格式,因为当导出excel时,内容中包含0作为第一个字符。 我尝试我objWorksheet.Range("B:B").NumberFormat = "@";
在行objWorksheet.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;
我通过添加objWorksheet.Range("B:B").NumberFormat = "00000";
得到了答案objWorksheet.Range("B:B").NumberFormat = "00000";
在行objWorksheet.columns.autofit;