小工具整理
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
--必须安装有excel才能进行操作,否则报错
|
||||
|
||||
-- 创建Excel应用程序对象
|
||||
excelApp = createOLEObject "Excel.Application"
|
||||
|
||||
-- 显示Excel应用程序
|
||||
excelApp.Visible = false
|
||||
|
||||
-- 创建一个新的工作簿
|
||||
--workbook = excelApp.Workbooks.Add()
|
||||
workbook=excelApp.Workbooks.open(excelFile)
|
||||
|
||||
-- 获取活动工作表
|
||||
sheet = workbook.ActiveSheet
|
||||
|
||||
-- 写入数据到单元格A1
|
||||
(sheet.Cells 1 1).Value = "Hello"
|
||||
(sheet.Cells 1 2).Value = "World!"
|
||||
|
||||
-- 保存工作簿到指定路径
|
||||
--workbook.SaveAs "D:\\Desktop\\123.xlsx"
|
||||
workbook.Save()
|
||||
|
||||
-- 关闭工作簿
|
||||
workbook.Close()
|
||||
|
||||
-- 退出Excel应用程序
|
||||
excelApp.Quit()
|
||||
|
||||
|
||||
/*-- Startup Ops
|
||||
-- Generate a filename
|
||||
--这里是excel文件的绝对路径
|
||||
excelFile = "D:\\Desktop\\123.xlsx"
|
||||
|
||||
-- Start an Excel OLE Object
|
||||
x = CreateOLEObject "Excel.Application"
|
||||
|
||||
-- Create a new workbook in the new excel document
|
||||
x.application.Workbooks.open(excelFile)
|
||||
|
||||
-- This makes Excel Visible
|
||||
-- true的话脚本运行时看到打开excel
|
||||
x.visible = false
|
||||
|
||||
--示例 获取表中1,1位置的数据
|
||||
pictureNum = (x.ActiveSheet.Cells 1 1).Value
|
||||
(x.ActiveSheet.Cells 1 1).Value="12345"
|
||||
|
||||
--之后是释放操作,如果未执行会导致excel文件一直被占用,只能以只读被打开
|
||||
-- Cleanup Ops
|
||||
-- Close the spreadsheet
|
||||
x.application.ActiveWorkbook.Close
|
||||
|
||||
-- quit excel
|
||||
x.quit()
|
||||
|
||||
-- Release the OLE Object
|
||||
releaseOLEObject x
|
||||
|
||||
-- Release ALL OLE Objects, just in case
|
||||
releaseAllOLEObjects()
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user