<script>
excelApp = new ActiveXObject("Excel.Application");
excelSheet = new ActiveXObject("Excel.Sheet");
// 使 Excel 通过 Application 对象可见。
excelSheet.Application.Visible = true;
// 将一些文本放置到表格中。
excelSheet.ActiveSheet.Cells(1,1).Value = "这是第一行第一列";
excelSheet.ActiveSheet.Cells(2,1).Value = "这是第二行第一列";
excelSheet.ActiveSheet.Cells(2,2).Value = "这是第二行第二列";
// 保存表格。
excelSheet.SaveAs("C:/excelTest.xls");
// 用 Application 对象用 Quit 方法关闭 Excel。
excelSheet.Application.Quit();
</script>
excelApp = new ActiveXObject("Excel.Application");
excelSheet = new ActiveXObject("Excel.Sheet");
// 使 Excel 通过 Application 对象可见。
excelSheet.Application.Visible = true;
// 将一些文本放置到表格中。
excelSheet.ActiveSheet.Cells(1,1).Value = "这是第一行第一列";
excelSheet.ActiveSheet.Cells(2,1).Value = "这是第二行第一列";
excelSheet.ActiveSheet.Cells(2,2).Value = "这是第二行第二列";
// 保存表格。
excelSheet.SaveAs("C:/excelTest.xls");
// 用 Application 对象用 Quit 方法关闭 Excel。
excelSheet.Application.Quit();
</script>
本文介绍了一种利用VBA(Visual Basic for Applications)脚本自动化创建并保存Excel文件的方法。通过实例展示了如何新建Excel应用实例、设置可见性、在指定单元格输入文本以及保存文件等操作。
2096

被折叠的 条评论
为什么被折叠?



