Sign in to follow this  
Followers 0
chinadhlhmgc

(help) spreadsheet Event question?

1 post in this topic

#NoTrayIcon
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>

Dim $oMyError
Dim $i
Dim $j

Global $oExcelEvt
;Declare objects
Dim $oExcel
$oExcel = ObjCreate("OWC10.spreadsheet.10")     ; Default to Office XP
If not IsObj($oExcel) Then
    $oExcel = ObjCreate("OWC11.spreadsheet.11") ; Office 2003   
EndIf
IF not IsObj($oExcel) Then
    $oExcel = ObjCreate("OWC00.spreadsheet")    ; Office 2000
EndIf
    If IsObj($oExcel) Then
        $oExcelEvt = ObjEvent($oExcel,"Excel_")  ;event-with 事件处理

        with $oExcel
            .TitleBar.Caption = "wage"          ;titie-text
            .DisplayTitleBar = false            ;titlebar 标题
            .AllowPropertyToolbox = false       ;setup 显示“命令和选项”对话框
            .DisplayToolbar = true              ;commandbar 是否显示工具栏默认值为 true
            .DisplayOfficeLogo = true           ;logo 取消显示Office图标
            .DisplayHorizontalScrollBar = false ;H-Scroll 是否显示水平滚动条默认为true
            .DisplayVerticalScrollBar = false   ;V-Scroll 是否显示垂直滚动条,默认为True
            .DisplayWorkbookTabs = false        ;WorkbookTabs 工作表标签
 
            .DisplayPropertyToolbox = false
            .DisplayDesignTimeUI = false

            .EnableEvents = true    ;event
            .EnableUndo = false     ;undo 允许撤销

            .Activewindow.EnableResize = false
            .Activewindow.DisplayZeros = true
            ;.ViewableRange = "A1:D5"   ;可视区域设置
        EndWith
    Else
       MsgBox(0,"Reply","Not an Object",4)
       Exit(1)
   EndIf
   
;Main Gui
$From1 = GuiCreate("Excel Object", 802, 590)    ;,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS
$GUI_ActiveX = GUICtrlCreateObj($oExcel, 10, 10 , 780 , 550)
Change_Headings()
;$oExcel.Commands(10038).ExeCute    ;

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
    EndSelect
WEnd
Exit

Func Excel_CommandBeforeExecute($Command, $Can)
    ;############################################
    ;question :  $Can.Value=true invalid ?????
    ;############################################
    msgbox (48,0, "Command_Number: " & $Command)
    $Can.Value = true
EndFunc

Func Excel_BeforeContextMenu($x, $y, $Menu, $Cancel)
    ;############################################
    ;question :  change menu ????
    ;############################################
    ;Local $cmContextMenu[1]
EndFunc

Func Excel_EndEdit( $Accept, $FinalValue, $Cancel, $ErrorDescription )
    ;############################################
    ;account text with column "C" invalid ???????????????
    ;############################################
    if $oExcel.ActiveCell.Column=3 Then
        if Stringleft($FinalValue.value,1)<>"'" then
            $FinalValue.value = "'" & $FinalValue.value
        Endif
    Endif

EndFunc

Func Change_Headings()
    Local $hdrColHeadings
    Local $hdrRowHeadings
    ; Set a variable to the column headings in the active window.
    $hdrColHeadings = $oExcel.Activewindow.ColumnHeadings

    ; Set a variable to the row headings in the active window.
    $hdrRowHeadings = $oExcel.Activewindow.RowHeadings

    ; Set the headings of columns A through D.
    $hdrColHeadings(1).Caption = "name"
    $hdrColHeadings(2).Caption = "sex"
    $hdrColHeadings(3).Caption = "account"
    $hdrColHeadings(4).Caption = "money"
EndFunc

;This is Sven P's custom error handler
Func MyErrFunc()
  Local $HexNumber = hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
  Return SetError( $HexNumber )
Endfunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0