ReportX.ocx 需要先注册——运行 regsvr32 ReportX.ocx
示例:
Code: Select all
#NoEnv
#SingleInstance force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Gui, +LastFound
Gui, Add, ActiveX, w700 h600 vrx, ReportProj1.ReportX
Gui, Add, Button, ys , 修改单元格
Gui, Add, Button, Disabled, 获取单元格数据
Gui, Add, Button, , 显示隐藏左侧标杆
Gui, Add, Button, , 显示隐藏顶部标杆
Gui, Add, Button, , 保存
Gui, Add, Button, , 打开文件
Gui, Show
ComObjConnect(rx, reportX_Envents) ; 可以注册事件
Return
Button修改单元格:
rx.SetCellValue(2, 3, "测试") ; 设置第2列第3行单元格的文字
rx.SetCellBackColor(2, 3, 0xEFBC13) ; 设置第2列第3行单元格的背景颜色
rx.SetCellFontColor(2, 3, 0xFFFFFF) ; 设置第2列第3行单元格的文字颜色
GuiControl, Enable, 获取单元格数据
Return
Button获取单元格数据:
MsgBox, % rx.GetCellValue(2, 3)
Return
Button显示隐藏左侧标杆:
rx.PoleWidth := rx.PoleWidth ? 0 : 43
Return
Button显示隐藏顶部标杆:
rx.PoleHeight := rx.PoleHeight ? 0 : 17
Return
Button保存:
If !rxFile {
FileSelectFile, rxFile, s16, , 保存文件, ReportX文件(*.rpxe)
If rxFile
rxFile .= (rxFile ~= "i)\.rpxe$") ? "" : ".rpxe"
}
If rxFile {
rx.SaveReport(rxFile)
WinSetTitle,,, % rxFile
MsgBox, 64, 提示, 保存成功!
}
Return
Button打开文件:
FileSelectFile, rxFile, 1, , 打开文件, ReportX文件(*.rpxe)
If rxFile {
rx.OpenReport(rxFile)
WinSetTitle,,, % rxFile
}
Return
GuiDropFiles:
If (A_GuiEvent ~= "i)\.rpxe") {
rx.OpenReport(rxFile := A_GuiEvent)
WinSetTitle,,, % rxFile
}
Return
GuiClose:
ExitApp
确保已注册ReportX() {
static _Init := 确保已注册ReportX()
If !ComObjCreate("ReportProj1.ReportX") {
If FileExist("ReportX.ocx")
RunWait, regsvr32 /s ReportX.ocx
Else {
MsgBox, 48, 错误, ReportX组件未注册、缺少文件ReportX.ocx!
ExitApp
}
}
Return True
}
class reportX_Envents {
OnCellChanged(aCol, aRow, aCellValue) {
ToolTip, % "aCol: " aCol . "`n"
. "aRow: " aRow . "`n"
. "aCellValue: " aCellValue
}
}