Exceldatenblatterstellung per GUI-Combo

  • Tach zusammen

    Ein neuer Tag, ein neues Problem :thumbup:

    Falls ihr mir mal wieder Euer Auge leihen mögt, das hier wird ein wenig konfuser. *g Alsoooooo...

    Ich bastel ja gerade - mit Eurer Hilfe - an einem Skript, welches mir meinen Tätigkeitsnachweis für die Firma etwas vereinfachen soll. (Also Programme auf, Programme zu, Datenblätter automatisch erstellen usw.) Jetzt hat sich unsere, stets unter Überlastung stehende, Buchhaltung etwas Neues ausgedacht. Ich mußte bisher einen Zettel am Monatsende abgeben, der alle Fahrten von mir aufführte. Dieser Zettel sah mal so aus:

    [Blockierte Grafik: http://s8.directupload.net/images/081001/7q52tmlp.jpg]


    Alle Fahrten lassen sich in vier Gruppen einteilen, jede Gruppe hat maximal fünf verschiedene Start- und Zielpositionen und jede Gruppe wird buchhalterisch über ein anderes Konto abgerechnet. Unsere Buchhaltung will jetzt, daß jede Fahrt einer Gruppe auf einem Extrazettel steht. Weil das einen Haufen Arbeit darstellt, brauche ich jetzt ein GUI, wo ich die Positionen Tag, Fahrstrecke von bis, Zeit Anfang Ende und Zweck aus Combos, bzw "CreateDate" auswählen und diese am Ende der Zeile einer Gruppe zuweisen kann. Angefangen habe ich so:

    Spoiler anzeigen

    #include <GUIConstants.au3>


    GUICreate("Formular", 1000) ; will create a dialog box that when displayed is centered

    ; Feld 1 Reihe 1 Datum
    $DTS_SHORTDATEFORMAT = 2
    $F1R1=GUICtrlCreateDate ( "Datum", 10, 10, 100, 20, $DTS_SHORTDATEFORMAT)
    GUISetState () ; will display an empty dialog box with a combo control with focus on

    ;Do
    ; $msg11 = GUIGetMsg()
    ; if $msg11 = $F1R1 then
    ; msgbox(0,"list=", GUICtrlRead($F1R1)) ; display the value
    ; endif
    ;Until $msg11 = $GUI_EVENT_CLOSE


    ;Feld 2 Reihe 1 Kilometer
    GUICtrlCreateCombo ("km", 120,10,50)
    GUICtrlSetData(-1,"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    GUISetState ()

    ; Feld 3 Reihe 1 Fahrstrecke "von"
    GUICtrlCreateCombo ("Strecke von", 180,10,170)
    GUICtrlSetData(-1,"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    GUISetState ()


    ; Feld 4 Reihe 1 Fahrstrecke "bis"
    GUICtrlCreateCombo ("Strecke bis", 360,10,170)
    GUICtrlSetData(-1,"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "bis")
    GUISetState ()

    ; Feld 5 Reihe 1 Zeit Beginn
    $DTS_TIMEFORMAT = 9
    $n=GUICtrlCreateDate ( "", 540, 10, 100, 20, $DTS_TIMEFORMAT)
    GUISetState ()

    ; Feld 6 Reihe 1 Zeit Ende
    $DTS_TIMEFORMAT = 9
    $n=GUICtrlCreateDate ( "", 650, 10, 100, 20, $DTS_TIMEFORMAT)
    GUISetState ()

    ; Feld 7 Reihe 1 Zweck der Fahrt
    GUICtrlCreateCombo ("Zweck", 760,10,170)
    GUICtrlSetData(-1,"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    GUISetState ()


    ; Feld 1 Reihe 2 Datum
    $DTS_SHORTDATEFORMAT = 2
    $n=GUICtrlCreateDate ( "Datum", 10, 40, 100, 20, $DTS_SHORTDATEFORMAT)
    GUISetState () ; will display an empty dialog box with a combo control with focus on

    ;Feld 2 Reihe 2 Kilometer
    GUICtrlCreateCombo ("km", 120,40,50)
    GUICtrlSetData(-1,"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    GUISetState ()

    ; Feld 3 Reihe 2 Fahrstrecke "von"
    GUICtrlCreateCombo ("Strecke von", 180,40,170)
    GUICtrlSetData(-1,"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    GUISetState ()


    ; Feld 4 Reihe 2 Fahrstrecke "bis"
    GUICtrlCreateCombo ("Strecke bis", 360,40,170)
    GUICtrlSetData(-1,"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "von")
    GUISetState ()

    ; Feld 5 Reihe 2 Zeit Beginn
    $DTS_TIMEFORMAT = 9
    $n=GUICtrlCreateDate ( "", 540, 40, 100, 20, $DTS_TIMEFORMAT)
    GUISetState ()

    ; Feld 6 Reihe 2 Zeit Ende
    $DTS_TIMEFORMAT = 9
    $n=GUICtrlCreateDate ( "", 650, 40, 100, 20, $DTS_TIMEFORMAT)
    GUISetState ()

    ; Feld 7 Reihe 2 Zweck der Fahrt
    GUICtrlCreateCombo ("Zweck", 760,40,170)
    GUICtrlSetData(-1,"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    GUISetState ()


    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend


    Es funktioniert soweit. Über die ausgeklammerte Do-Until bekomme ich auch den Wert des ersten Feldes als MsgBox zurück. Ich fürchte aber, hier muß mit Arrays gearbeitet werden, richtig? (Wie Bugfix richtig erkannte, kommt hier die Stelle, die für Knoten im Hirn sorgt. *g) Ich hab die Tutorials im Wiki und von Bugfix gelesen... nicht durchgearbeitet, nur gelesen. Bin ich da auf der richtigen Spur? Ich stelle mir das so vor, das die Eingaben in eine Datei geschrieben, von dort ausgelesen und in eine Exceltabelle übertragen werden. (Vielleicht über die Koordinaten jeder Zelle). Dieses GUI müßte sich zudem jeden Eintrag merken, das bereits getätigte Eingaben nicht gelöscht oder überschrieben werden.

    Ist so etwas (für mich) machbar, oder bleibe ich besser bei Papier und Bleistift? *fg

    Liebe Grüße,
    Reinhold.

    Einmal editiert, zuletzt von Arioch (1. Oktober 2008 um 14:10)

  • Hi Bugfix :)

    Danke Dir! :)

    Liebe Grüße,
    Reinhold.

    P.S.: Bin mal eben 2 Stunden afk, dem Oktoberzettel eine neue Zeile hinzufügen! *g

    2 Mal editiert, zuletzt von Arioch (1. Oktober 2008 um 11:04)

    • Offizieller Beitrag

    Hi,
    so - ich habe dein Skript erst mal etwas ( gewaltig :P ) optimiert. Da schreibst du dich ja tot bei. :whistling:
    Ich brauche mal noch die Struktur deiner Excel-Tabelle, um die Daten dort einzutragen. Im Bsp. lese ich einfach in die Console aus.

    Spoiler anzeigen
    [autoit]

    #include <DateTimeConstants.au3>
    #include <GUIConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $arCtrlID[10][7] ; 10 Zeilen, 7 Spalten <== Formular
    Global $y0 = 10
    Global $arCtrlSize[7][2] = [ _ ; 7 Controls je Zeile, 2 Werte: CtrlErstellgCmd_1, CtrlErstellgCmd_2
    ["GUICtrlCreateDate('Datum', 10,",", 100, 20, $DTS_SHORTDATEFORMAT)"], _
    ["GUICtrlCreateCombo('km', 120,",", 50)"], _
    ["GUICtrlCreateCombo('Strecke von', 180,",", 170)"], _
    ["GUICtrlCreateCombo('Strecke bis', 360,",", 170)"], _
    ["GUICtrlCreateDate('', 540,",", 100, 20, $DTS_TIMEFORMAT)"], _
    ["GUICtrlCreateDate('', 650,",", 100, 20, $DTS_TIMEFORMAT)"], _
    ["GUICtrlCreateCombo('Zweck', 760,",", 170)"]]

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Formular", 940, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    ; Erstellen Controls:
    For $i = 0 To UBound($arCtrlID) -1
    For $k = 0 To UBound($arCtrlSize) -1
    ; y-Wert für akt. Zeile einfügen u. Ctrl erstellen
    $arCtrlID[$i][$k] = Execute($arCtrlSize[$k][0] & ($y0 + $i*35) & $arCtrlSize[$k][1])
    Next
    Next
    GUICtrlCreateButton("Daten Übertragen", 830, 365, 100, 20)
    GUICtrlSetOnEvent(-1, "_ReadData")
    ; Daten einfügen:
    For $i = 0 To UBound($arCtrlID) -1
    For $k = 0 To UBound($arCtrlID, 2) -1
    Switch $k
    Case 1
    GUICtrlSetData($arCtrlID[$i][$k],"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    Case 2
    GUICtrlSetData($arCtrlID[$i][$k],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    Case 3
    GUICtrlSetData($arCtrlID[$i][$k],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "bis")
    Case 6
    GUICtrlSetData($arCtrlID[$i][$k],"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    EndSwitch
    Next
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ReadData() ; Inhalt aus Datenfeldern auslesen, bricht ab, wenn eine Zeile o. Eintrag (km als Prüfwert)
    For $i = 0 To UBound($arCtrlID) -1
    If GUICtrlRead($arCtrlID[$i][1]) = "km" Then Return
    ; hier testweise als String ausgelesen:
    $str = ''
    For $k = 0 To UBound($arCtrlID, 2) -1
    $str &= GUICtrlRead($arCtrlID[$i][$k]) & "|"
    Next
    ConsoleWrite(StringTrimRight($str, 1) & @CRLF)
    Next
    EndFunc

    [/autoit]

    Edit:
    Hier mal noch eine Variante mit ListView, finde ich ansprechender als 1000 Controls ;)

    Spoiler anzeigen
    [autoit]

    #include <DateTimeConstants.au3>
    #Include <GuiListView.au3>
    #include <GUIConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $arCtrlID[7]

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Formular", 940, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    $arCtrlID[0] = GUICtrlCreateDate('Datum', 10, 10, 100, 20, $DTS_SHORTDATEFORMAT)
    $arCtrlID[1] = GUICtrlCreateCombo('km', 120, 10, 50)
    $arCtrlID[2] = GUICtrlCreateCombo('Strecke von', 180, 10, 170)
    $arCtrlID[3] = GUICtrlCreateCombo('Strecke bis', 360, 10, 170)
    $arCtrlID[4] = GUICtrlCreateDate('', 540, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[5] = GUICtrlCreateDate('', 650, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[6] = GUICtrlCreateCombo('Zweck', 760, 10, 170)
    $hListView = GUICtrlCreateListView("Datum|km|Von|Bis|Abfahrt|Ankunft|Zweck", 10, 35, 920, 320, Default, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    _GUICtrlListView_SetColumnWidth($hListView, 0, 105)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 3, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 4, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 5, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 6, $LVSCW_AUTOSIZE_USEHEADER )
    GUICtrlCreateButton("In &Liste Übernehmen", 10, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_ReadData")
    GUICtrlCreateButton("Daten &Übertragen", 810, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_Transfer")
    ; Daten einfügen:
    For $i = 0 To UBound($arCtrlID) -1
    Switch $i
    Case 1
    GUICtrlSetData($arCtrlID[$i],"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    Case 2
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    Case 3
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "bis")
    Case 6
    GUICtrlSetData($arCtrlID[$i],"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    EndSwitch
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ReadData() ; Inhalt aus Datenfeldern auslesen und in Liste schreiben, bricht ab, wenn kein Eintrag bei km
    If GUICtrlRead($arCtrlID[1]) = "km" Then Return
    $str = ''
    For $i = 0 To UBound($arCtrlID) -1
    $str &= GUICtrlRead($arCtrlID[$i]) & "|"
    Next
    GUICtrlCreateListViewItem(StringTrimRight($str, 1), $hListView)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Transfer()
    MsgBox(0, '', 'Noch nicht belegt')
    EndFunc

    [/autoit]
  • Ich ziehe meinen Hut und fresse ihn auf! :whistling: (Wenn ich nicht schon Fahrradfahren und "Mit-Messer-und-Gabel-essen" gelernt hätte, würde ich jetzt sagen, daß schaff' ich nie. Aber so hab ich ja noch Hoffnung! *g)

    Wenn ich jetzt sage "Danke für Deine Hilfe", wär das wohl *etwas* untertrieben. Danke fürs Coding!!! Hätte ich nie so hinbekommen. Ich schwör! Ich werde übrigens ebenfalls die zweite Variante verwenden! *lach

    Eine MusterExcelTabelle habe ich an mein erstes Posting gehangen.

    Gedemütigte Grüße :D
    Reinhold!

    Einmal editiert, zuletzt von Arioch (1. Oktober 2008 um 14:11)

    • Offizieller Beitrag

    Hi,
    hier das Ganze mit Transfer an Excel-Datei.

    Spoiler anzeigen
    [autoit]

    #include <DateTimeConstants.au3>
    #Include <GuiListView.au3>
    #include <GUIConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $arCtrlID[7]
    Global $ExelPath = @ScriptDir & '\Test.xls'
    ; Muster Excel-Tabelle - Spalten: A = Datum; B = km; C = Von; D = Bis; E = Ab; F = An; G = Zweck
    ; Wenn nicht vorhanden, wird sie erstellt

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Formular", 940, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    $arCtrlID[0] = GUICtrlCreateDate('Datum', 10, 10, 100, 20, $DTS_SHORTDATEFORMAT)
    $arCtrlID[1] = GUICtrlCreateCombo('km', 120, 10, 50)
    $arCtrlID[2] = GUICtrlCreateCombo('Strecke von', 180, 10, 170)
    $arCtrlID[3] = GUICtrlCreateCombo('Strecke bis', 360, 10, 170)
    $arCtrlID[4] = GUICtrlCreateDate('', 540, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[5] = GUICtrlCreateDate('', 650, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[6] = GUICtrlCreateCombo('Zweck', 760, 10, 170)
    $hListView = GUICtrlCreateListView("Datum|km|Von|Bis|Abfahrt|Ankunft|Zweck", 10, 35, 920, 320, Default, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    _GUICtrlListView_SetColumnWidth($hListView, 0, 105)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 3, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 4, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 5, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 6, $LVSCW_AUTOSIZE_USEHEADER )
    GUICtrlCreateButton("In &Liste Übernehmen", 10, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_ReadData")
    GUICtrlCreateButton("Daten &Übertragen", 810, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_Transfer")
    ; Daten einfügen:
    For $i = 0 To UBound($arCtrlID) -1
    Switch $i
    Case 1
    GUICtrlSetData($arCtrlID[$i],"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    Case 2
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    Case 3
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "bis")
    Case 6
    GUICtrlSetData($arCtrlID[$i],"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    EndSwitch
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ReadData() ; Inhalt aus Datenfeldern auslesen und in Liste schreiben, bricht ab, wenn kein Eintrag bei km
    If GUICtrlRead($arCtrlID[1]) = "km" Then Return
    $str = ''
    For $i = 0 To UBound($arCtrlID) -1
    $str &= GUICtrlRead($arCtrlID[$i]) & "|"
    Next
    GUICtrlCreateListViewItem(StringTrimRight($str, 1), $hListView)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Transfer()
    Local $count = _GUICtrlListView_GetItemCount($hListView), $oExcel
    If $count < 1 Then Return
    If Not FileExists($ExelPath) Then
    $oExcel = _ExcelBookNew(0)
    $oExcel.Activesheet.Range("A1").Value = "DATUM"
    $oExcel.Activesheet.Range("B1").Value = "KM"
    $oExcel.Activesheet.Range("C1").Value = "VON"
    $oExcel.Activesheet.Range("D1").Value = "BIS"
    $oExcel.Activesheet.Range("E1").Value = "AB"
    $oExcel.Activesheet.Range("F1").Value = "AN"
    $oExcel.Activesheet.Range("G1").Value = "ZWECK"
    _ExcelBookSaveAs($oExcel, $ExelPath)
    _ExcelBookClose($oExcel)
    EndIf
    $oExcel = _ExcelBookOpen($ExelPath, 0)
    Local $Row = _ExcelBookGetWidth($oExcel, 2) +1
    For $i = 0 To $count -1 ; Daten jeder Zeile an Exel-Tabelle übertragen
    $oExcel.Activesheet.Range("A" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 0)
    $oExcel.Activesheet.Range("A" & $Row+$i).NumberFormat = "TT.MM.JJJJ"
    $oExcel.Activesheet.Range("B" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 1)
    $oExcel.Activesheet.Range("C" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 2)
    $oExcel.Activesheet.Range("D" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 3)
    $oExcel.Activesheet.Range("E" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 4)
    $oExcel.Activesheet.Range("F" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 5)
    $oExcel.Activesheet.Range("G" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 6)
    Next
    _GUICtrlListView_DeleteAllItems($hListView)
    _ExcelBookClose($oExcel)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function: _ExcelBookGetWidth($oExcel [, $iTyp=1 [, $iHeader=1 [, $sCol='A']]])
    ; Description: Gibt die letzte belegte Zeile und/oder Spalte einer Tabelle zurück
    ; Syntax: _ExcelBookGetWidth($oExcel, $iTyp=1, $iHeader=1, $sCol='A')
    ; Parameter(s): $oExcel - Referenz eines geöffneten Excel Objekts
    ; $iTyp - 1=letzte Spalte (Standard); 2=letzte Zeile; 3=Spalte|Zeile
    ; $iHeader - Nummer der Zeile, in der die letzte Spalte gesucht wird
    ; $$sCol - Buchstabe der Spalte, in der die letzte Zeile gesucht wird
    ; Return Value(s): Erfolg - letzte Spalte und/oder Zeile
    ; Ist die Zeile oder Spalte leer, wird '0' zurückgegeben
    ; Fehler - 0 und setzt @error:
    ; @error=1 - Objekt existiert nicht
    ; @error=2 - $iTyp oder $iHeader außerhalb des Wertebereichs (1 - 65536)
    ; @error=3 - $sCol außerhalb des Wertebereichs (A - IV)
    ; Requirement(s): $iHeader bzw. $sCol sind durchgängig bis zum letzten Zeilen-/Spaltenelement belegt
    ; Author(s): BugFix ( [email='bugfix@autoit.de'][/email] )
    ;==================================================================================================
    Func _ExcelBookGetWidth($oExcel, $iTyp=1, $iHeader=1, $sCol='A')
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $iTyp < 1 Or $iHeader < 1 Or $iTyp > 65536 Or $iHeader > 65536 Then Return SetError(2, 0, 0)
    $sCol = StringUpper($sCol)
    If StringLen($sCol) = 2 Then
    Local $str = StringSplit($sCol, '')
    If Asc($str[1]) < 65 Or Asc($str[1]) > 73 Then Return SetError(3, 0, 0)
    If Asc($str[2]) < 65 Or Asc($str[2]) > 90 Or _
    (Asc($str[1]) = 73 And Asc($str[2]) > 86) Then Return SetError(3, 0, 0)
    ElseIf StringLen($sCol) > 2 Then
    Return SetError(3, 0, 0)
    EndIf
    If Asc($sCol) < 65 Or Asc($sCol) > 90 Then Return SetError(3, 0, 0)
    Local $sColOut, $iRowOut
    Select
    Case $iTyp = 1 Or $iTyp = 3
    For $i = 65 To 90
    If $oExcel.Activesheet.Range(Chr($i) & $iHeader).Value = '' Then
    If $i = 65 Then
    $sColOut = 0
    Else
    $sColOut = Chr($i-1)
    EndIf
    ExitLoop
    EndIf
    If $i = 90 Then
    For $j = 65 To 73
    For $k = 65 To 90
    If $j = 73 And $k = 87 Then
    $sColOut = Chr($j) & Chr($k-1)
    ExitLoop
    EndIf
    If $oExcel.Activesheet.Range(Chr($j) & Chr($k)).Value = '' Then
    If $k = 65 Then
    $sColOut = Chr($j)
    Else
    $sColOut = Chr($j) & Chr($k-1)
    EndIf
    ExitLoop
    EndIf
    Next
    Next
    EndIf
    Next
    ContinueCase
    Case $iTyp = 2
    For $i = 1 To 65536
    If $oExcel.Activesheet.Range($sCol & $i).Value = '' Then
    $iRowOut = $i -1
    ExitLoop
    EndIf
    Next
    EndSelect
    Switch $iTyp
    Case 1
    Return $sColOut
    Case 2
    Return $iRowOut
    Case 3
    Return $sColOut & '|' & $iRowOut
    EndSwitch
    EndFunc ;==>_ExcelBookGetWidth

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Creates new workbook and returns its object identifier.
    ; Syntax: $oExcel = _ExcelBookNew($fVisible = 1)
    ; Parameter(s): $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns new object identifier
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Unable to create the Excel COM object
    ; @error=2 - $fVisible parameter is not a number
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookNew($fVisible = 1)
    $oExcel = ObjCreate("Excel.Application")
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If NOT IsNumber($fVisible) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
    .Visible = $fVisible
    .WorkBooks.Add
    .ActiveWorkbook.Sheets(1).Select()
    EndWith
    Return $oExcel
    EndFunc ;==>_ExcelBookNew

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Opens an existing workbook and returns its object identifier.
    ; Syntax: $oExcel = _ExcelBookOpen($sFilePath, $fVisible = 1)
    ; Parameter(s): sFilePath - Path and filename of the file to be opened
    ; $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1)
    ; $fReadOnly - Flag, whether to open the workbook as read-only (True or False) (default=False)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns new object identifier
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File does not exist
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False)
    $oExcel = ObjCreate("Excel.Application")
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If NOT FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
    .Visible = $fVisible
    .WorkBooks.Open($sFilePath, Default, $fReadOnly)
    .ActiveWorkbook.Sheets(1).Select()
    EndWith
    Return $oExcel
    EndFunc ;==>_ExcelBookOpen

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Saves the active workbook of the specified Excel object.
    ; Syntax: _ExcelBookSave($oExcel, $fAlerts = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookSave($oExcel, $fAlerts = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    With $oExcel
    .Application.DisplayAlerts = $fAlerts
    .Application.ScreenUpdating = $fAlerts
    .ActiveWorkBook.Save
    If NOT $fAlerts Then
    .Application.DisplayAlerts = 1
    .Application.ScreenUpdating = 1
    EndIf
    EndWith
    Return 1
    EndFunc ;==>_ExcelBookSave

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Saves the active workbook of the specified Excel object with a new filename and/or type.
    ; Syntax: _ExcelSaveDocAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $sFilePath - Path and filename of the file to be read
    ; $sType - Excel writable filetype string = "xls|csv|txt|template|html", default "xls"
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; $fOverWrite - Flag for overwriting the file, if it already exists (0=no, 1=yes)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - Invalid filetype string
    ; @error=3 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot net>
    ; Note(s): You can only SaveAs back to the same working path the workbook was originally opened from at this time
    ; (not applicable to newly created, unsaved books).
    ;
    ;===============================================================================
    Func _ExcelBookSaveAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $sType = "xls" or $sType = "csv" or $sType = "txt" or $sType = "template" or $sType = "html" Then
    If $sType = "xls" Then $sType = -4143
    If $sType = "csv" Then $sType = 24
    If $sType = "txt" Then $sType = 20
    If $sType = "template" Then $sType = 17
    If $sType = "html" Then $sType = 44
    Else
    Return SetError(2, 0, 0)
    EndIf
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    $oExcel.Application.DisplayAlerts = $fAlerts
    $oExcel.Application.ScreenUpdating = $fAlerts
    If FileExists($sFilePath) Then
    If NOT $fOverWrite Then Return SetError(3, 0, 0)
    FileDelete($sFilePath)
    EndIf
    $oExcel.ActiveWorkBook.SaveAs ($sFilePath, $sType)
    If NOT $fAlerts Then
    $oExcel.Application.DisplayAlerts = 1
    $oExcel.Application.ScreenUpdating = 1
    EndIf
    Return 1
    EndFunc ;==>_ExcelBookSaveAs

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Closes the active workbook and removes the specified Excel object.
    ; Syntax: _ExcelCloseDoc($oExcel, $fSave = 1, $fAlerts = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $fSave - Flag for saving the file before closing (0=no save, 1=save)
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $fSave > 1 Then $fSave = 1
    If $fSave < 0 Then $fSave = 0
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    $oExcel.Application.DisplayAlerts = $fAlerts
    $oExcel.Application.ScreenUpdating = $fAlerts
    If $fSave Then
    $oExcel.ActiveWorkBook.Save
    EndIf
    $oExcel.Application.DisplayAlerts = True
    $oExcel.Application.ScreenUpdating = True
    $oExcel.Quit
    Return 1
    EndFunc ;==>_ExcelBookClose

    [/autoit]
  • Und hier Dein erweitertes Skript mit den Funktionen (und Button) "Eintrag löschen" (funktionsfähig) und "Eintrage sortieren" (noch im Versuchsstadium)

    Spoiler anzeigen
    [autoit]

    #include <DateTimeConstants.au3>
    #Include <GuiListView.au3>
    #include <GUIConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $arCtrlID[7]
    Global $ExelPath = @ScriptDir & '\Test.xls'
    ; Muster Excel-Tabelle - Spalten: A = Datum; B = km; C = Von; D = Bis; E = Ab; F = An; G = Zweck
    ; Wenn nicht vorhanden, wird sie erstellt

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Formular", 940, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    $arCtrlID[0] = GUICtrlCreateDate('Datum', 10, 10, 100, 20, $DTS_SHORTDATEFORMAT)
    $arCtrlID[1] = GUICtrlCreateCombo('km', 120, 10, 50)
    $arCtrlID[2] = GUICtrlCreateCombo('Strecke von', 180, 10, 170)
    $arCtrlID[3] = GUICtrlCreateCombo('Strecke bis', 360, 10, 170)
    $arCtrlID[4] = GUICtrlCreateDate('', 540, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[5] = GUICtrlCreateDate('', 650, 10, 100, 20, $DTS_TIMEFORMAT)
    $arCtrlID[6] = GUICtrlCreateCombo('Zweck', 760, 10, 170)
    $hListView = GUICtrlCreateListView("Datum|km|Von|Bis|Abfahrt|Ankunft|Zweck", 10, 35, 920, 320, Default, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    _GUICtrlListView_SetColumnWidth($hListView, 0, 105)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 3, 180)
    _GUICtrlListView_SetColumnWidth($hListView, 4, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 5, 110)
    _GUICtrlListView_SetColumnWidth($hListView, 6, $LVSCW_AUTOSIZE_USEHEADER )
    GUICtrlCreateButton("In &Liste Übernehmen", 10, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_ReadData")
    GUICtrlCreateButton("&Eintrag löschen", 310, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_Eintragloeschen")
    GUICtrlCreateButton("Einträge &sortieren", 510, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_sort")
    GUICtrlCreateButton("Daten &Übertragen", 810, 365, 120, 20)
    GUICtrlSetOnEvent(-1, "_Transfer")
    ; Daten einfügen:
    For $i = 0 To UBound($arCtrlID) -1
    Switch $i
    Case 1
    GUICtrlSetData($arCtrlID[$i],"3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", "km")
    Case 2
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|innerhalb", "von")
    Case 3
    GUICtrlSetData($arCtrlID[$i],"Seefeld, Krummenseer Cha|Werneuchen Markt|Bernau Zentrale|Werneuchen", "bis")
    Case 6
    GUICtrlSetData($arCtrlID[$i],"2. Zustellung Schötzau|Verteilung Briefe|Fahrt zum Bezirk", "Zweck")
    EndSwitch
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Eintragloeschen()
    _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($hListView))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _sort()
    MsgBox(0, '', 'Noch nicht belegt')
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ReadData() ; Inhalt aus Datenfeldern auslesen und in Liste schreiben, bricht ab, wenn kein Eintrag bei km
    If GUICtrlRead($arCtrlID[1]) = "km" Then Return
    $str = ''
    For $i = 0 To UBound($arCtrlID) -1
    $str &= GUICtrlRead($arCtrlID[$i]) & "|"
    Next
    GUICtrlCreateListViewItem(StringTrimRight($str, 1), $hListView)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Transfer()
    Local $count = _GUICtrlListView_GetItemCount($hListView), $oExcel
    If $count < 1 Then Return
    If Not FileExists($ExelPath) Then
    $oExcel = _ExcelBookNew(0)
    $oExcel.Activesheet.Range("A1").Value = "DATUM"
    $oExcel.Activesheet.Range("B1").Value = "KM"
    $oExcel.Activesheet.Range("C1").Value = "VON"
    $oExcel.Activesheet.Range("D1").Value = "BIS"
    $oExcel.Activesheet.Range("E1").Value = "AB"
    $oExcel.Activesheet.Range("F1").Value = "AN"
    $oExcel.Activesheet.Range("G1").Value = "ZWECK"
    _ExcelBookSaveAs($oExcel, $ExelPath)
    _ExcelBookClose($oExcel)
    EndIf
    $oExcel = _ExcelBookOpen($ExelPath, 0)
    Local $Row = _ExcelBookGetWidth($oExcel, 2) +1
    For $i = 0 To $count -1 ; Daten jeder Zeile an Exel-Tabelle übertragen
    $oExcel.Activesheet.Range("A" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 0)
    $oExcel.Activesheet.Range("A" & $Row+$i).NumberFormat = "TT.MM.JJJJ"
    $oExcel.Activesheet.Range("B" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 1)
    $oExcel.Activesheet.Range("C" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 2)
    $oExcel.Activesheet.Range("D" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 3)
    $oExcel.Activesheet.Range("E" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 4)
    $oExcel.Activesheet.Range("F" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 5)
    $oExcel.Activesheet.Range("G" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 6)
    Next
    _GUICtrlListView_DeleteAllItems($hListView)
    _ExcelBookClose($oExcel)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function: _ExcelBookGetWidth($oExcel [, $iTyp=1 [, $iHeader=1 [, $sCol='A']]])
    ; Description: Gibt die letzte belegte Zeile und/oder Spalte einer Tabelle zurück
    ; Syntax: _ExcelBookGetWidth($oExcel, $iTyp=1, $iHeader=1, $sCol='A')
    ; Parameter(s): $oExcel - Referenz eines geöffneten Excel Objekts
    ; $iTyp - 1=letzte Spalte (Standard); 2=letzte Zeile; 3=Spalte|Zeile
    ; $iHeader - Nummer der Zeile, in der die letzte Spalte gesucht wird
    ; $$sCol - Buchstabe der Spalte, in der die letzte Zeile gesucht wird
    ; Return Value(s): Erfolg - letzte Spalte und/oder Zeile
    ; Ist die Zeile oder Spalte leer, wird '0' zurückgegeben
    ; Fehler - 0 und setzt @error:
    ; @error=1 - Objekt existiert nicht
    ; @error=2 - $iTyp oder $iHeader außerhalb des Wertebereichs (1 - 65536)
    ; @error=3 - $sCol außerhalb des Wertebereichs (A - IV)
    ; Requirement(s): $iHeader bzw. $sCol sind durchgängig bis zum letzten Zeilen-/Spaltenelement belegt
    ; Author(s): BugFix ( [email='bugfix@autoit.de'][/email] )
    ;==================================================================================================
    Func _ExcelBookGetWidth($oExcel, $iTyp=1, $iHeader=1, $sCol='A')
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $iTyp < 1 Or $iHeader < 1 Or $iTyp > 65536 Or $iHeader > 65536 Then Return SetError(2, 0, 0)
    $sCol = StringUpper($sCol)
    If StringLen($sCol) = 2 Then
    Local $str = StringSplit($sCol, '')
    If Asc($str[1]) < 65 Or Asc($str[1]) > 73 Then Return SetError(3, 0, 0)
    If Asc($str[2]) < 65 Or Asc($str[2]) > 90 Or _
    (Asc($str[1]) = 73 And Asc($str[2]) > 86) Then Return SetError(3, 0, 0)
    ElseIf StringLen($sCol) > 2 Then
    Return SetError(3, 0, 0)
    EndIf
    If Asc($sCol) < 65 Or Asc($sCol) > 90 Then Return SetError(3, 0, 0)
    Local $sColOut, $iRowOut
    Select
    Case $iTyp = 1 Or $iTyp = 3
    For $i = 65 To 90
    If $oExcel.Activesheet.Range(Chr($i) & $iHeader).Value = '' Then
    If $i = 65 Then
    $sColOut = 0
    Else
    $sColOut = Chr($i-1)
    EndIf
    ExitLoop
    EndIf
    If $i = 90 Then
    For $j = 65 To 73
    For $k = 65 To 90
    If $j = 73 And $k = 87 Then
    $sColOut = Chr($j) & Chr($k-1)
    ExitLoop
    EndIf
    If $oExcel.Activesheet.Range(Chr($j) & Chr($k)).Value = '' Then
    If $k = 65 Then
    $sColOut = Chr($j)
    Else
    $sColOut = Chr($j) & Chr($k-1)
    EndIf
    ExitLoop
    EndIf
    Next
    Next
    EndIf
    Next
    ContinueCase
    Case $iTyp = 2
    For $i = 1 To 65536
    If $oExcel.Activesheet.Range($sCol & $i).Value = '' Then
    $iRowOut = $i -1
    ExitLoop
    EndIf
    Next
    EndSelect
    Switch $iTyp
    Case 1
    Return $sColOut
    Case 2
    Return $iRowOut
    Case 3
    Return $sColOut & '|' & $iRowOut
    EndSwitch
    EndFunc ;==>_ExcelBookGetWidth

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Creates new workbook and returns its object identifier.
    ; Syntax: $oExcel = _ExcelBookNew($fVisible = 1)
    ; Parameter(s): $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns new object identifier
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Unable to create the Excel COM object
    ; @error=2 - $fVisible parameter is not a number
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookNew($fVisible = 1)
    $oExcel = ObjCreate("Excel.Application")
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If NOT IsNumber($fVisible) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
    .Visible = $fVisible
    .WorkBooks.Add
    .ActiveWorkbook.Sheets(1).Select()
    EndWith
    Return $oExcel
    EndFunc ;==>_ExcelBookNew

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Opens an existing workbook and returns its object identifier.
    ; Syntax: $oExcel = _ExcelBookOpen($sFilePath, $fVisible = 1)
    ; Parameter(s): sFilePath - Path and filename of the file to be opened
    ; $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1)
    ; $fReadOnly - Flag, whether to open the workbook as read-only (True or False) (default=False)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns new object identifier
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File does not exist
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False)
    $oExcel = ObjCreate("Excel.Application")
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If NOT FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
    .Visible = $fVisible
    .WorkBooks.Open($sFilePath, Default, $fReadOnly)
    .ActiveWorkbook.Sheets(1).Select()
    EndWith
    Return $oExcel
    EndFunc ;==>_ExcelBookOpen

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Saves the active workbook of the specified Excel object.
    ; Syntax: _ExcelBookSave($oExcel, $fAlerts = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookSave($oExcel, $fAlerts = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    With $oExcel
    .Application.DisplayAlerts = $fAlerts
    .Application.ScreenUpdating = $fAlerts
    .ActiveWorkBook.Save
    If NOT $fAlerts Then
    .Application.DisplayAlerts = 1
    .Application.ScreenUpdating = 1
    EndIf
    EndWith
    Return 1
    EndFunc ;==>_ExcelBookSave

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Saves the active workbook of the specified Excel object with a new filename and/or type.
    ; Syntax: _ExcelSaveDocAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $sFilePath - Path and filename of the file to be read
    ; $sType - Excel writable filetype string = "xls|csv|txt|template|html", default "xls"
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; $fOverWrite - Flag for overwriting the file, if it already exists (0=no, 1=yes)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - Invalid filetype string
    ; @error=3 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot net>
    ; Note(s): You can only SaveAs back to the same working path the workbook was originally opened from at this time
    ; (not applicable to newly created, unsaved books).
    ;
    ;===============================================================================
    Func _ExcelBookSaveAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $sType = "xls" or $sType = "csv" or $sType = "txt" or $sType = "template" or $sType = "html" Then
    If $sType = "xls" Then $sType = -4143
    If $sType = "csv" Then $sType = 24
    If $sType = "txt" Then $sType = 20
    If $sType = "template" Then $sType = 17
    If $sType = "html" Then $sType = 44
    Else
    Return SetError(2, 0, 0)
    EndIf
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    $oExcel.Application.DisplayAlerts = $fAlerts
    $oExcel.Application.ScreenUpdating = $fAlerts
    If FileExists($sFilePath) Then
    If NOT $fOverWrite Then Return SetError(3, 0, 0)
    FileDelete($sFilePath)
    EndIf
    $oExcel.ActiveWorkBook.SaveAs ($sFilePath, $sType)
    If NOT $fAlerts Then
    $oExcel.Application.DisplayAlerts = 1
    $oExcel.Application.ScreenUpdating = 1
    EndIf
    Return 1
    EndFunc ;==>_ExcelBookSaveAs

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Closes the active workbook and removes the specified Excel object.
    ; Syntax: _ExcelCloseDoc($oExcel, $fSave = 1, $fAlerts = 0)
    ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $fSave - Flag for saving the file before closing (0=no save, 1=save)
    ; $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error on errors:
    ; @error=1 - Specified object does not exist
    ; @error=2 - File exists, overwrite flag not set
    ; Author(s): SEO <locodarwin at yahoo dot com>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $fSave > 1 Then $fSave = 1
    If $fSave < 0 Then $fSave = 0
    If $fAlerts > 1 Then $fAlerts = 1
    If $fAlerts < 0 Then $fAlerts = 0
    $oExcel.Application.DisplayAlerts = $fAlerts
    $oExcel.Application.ScreenUpdating = $fAlerts
    If $fSave Then
    $oExcel.ActiveWorkBook.Save
    EndIf
    $oExcel.Application.DisplayAlerts = True
    $oExcel.Application.ScreenUpdating = True
    $oExcel.Quit
    Return 1
    EndFunc ;==>_ExcelBookClose

    [/autoit]

    Nochmals vielen vielen Dank! :) (Ich habe gerade ein Datenblatt erstellt. Brauche nur mit Excel sonst eine halbe Stunde pro Seite. Jetzt liege ich bei unter 5 Minuten! :))

    • Offizieller Beitrag

    Hi,
    zum Sortieren brauchst du keinen Extra-Button. Das kannst du per Klick auf den Spaltenkopf lösen.
    Ich habe mal das Bsp. aus der Hilfe "entschlackt":

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $hListView

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("ListView SimpleSort", 400, 300)
    $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
    GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlCreateListViewItem("line4|5|more_a", $hListView)
    GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView)
    GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView)
    GUICtrlCreateListViewItem("line3|23|more_e", $hListView)
    GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView)
    GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView)
    GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView)
    GUICtrlCreateListViewItem("line1|10|more_b", $hListView)
    _GUICtrlListView_SetColumnWidth($hListView, 0, 75)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 75)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 75)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; die 2 Folgezeilen in dein Skript einfügen und die Func WM_NOTIFY
    ; dann kannst du per Klick auf den Spaltenkopf sortieren (auf/absteigend)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $LVN_COLUMNCLICK
    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Edit
    Und nun habe ich eine Anregung für dich :D
    Bau das ganze etwas um unter Einbeziehung dieses Postings: IntelliSenseBox
    Verwende statt der Datums-/Textfelder und Combos nur Inputfelder als IntellisenseBox.
    Ich vermute, du machst deine Abrechnung monatlich. Somit kannst du beim Start die möglichen Datumseinträge als Liste hinterlegen und mit max. 2 eingegebenen Ziffern hast du das richtige Datum (geht schneller als Mausklickerei). In den Combos geht das ja auch jetzt schon - könnte man aber auch ersetzen wegen der Optik ;) .
    Für die Zeit könntest du ein formatiertes Input erstellen, das dir den : automatisch setzt, sodass du einfach die Zeit 4-stellig hintereinander eingibst. Zum Formatieren findest du Infos im Forum.
    Wenn du das alles verwendest, brauchst du nicht mehr zur Maus greifen und schaffst dein Formular in 2 Minuten :D

  • warum denn input-felder nehmen, wenn es mit der Combo auch geht ?

    Spoiler anzeigen
    [autoit]

    #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GUIComboBox.au3>
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hCombo

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()

    [/autoit] [autoit][/autoit] [autoit]

    ; Create GUI
    GUICreate("ComboBox Auto Complete", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; Add files
    _GUICtrlComboBox_BeginUpdate($hCombo)
    _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($hCombo)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($hCombo) Then $hWndCombo = GUICtrlGetHandle($hCombo)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
    Case $hCombo, $hWndCombo
    Switch $iCode
    Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
    _GUICtrlComboBox_AutoComplete($hCombo)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]
  • Hi... bin wieder da! *g

    Hat eine Weile gedauert herauszufinden, wo im Skript ich die beiden Zeilen

    [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

    [/autoit]

    einsetzen muß, um Fehlermeldungen zu vermeiden. Klappt jetzt aber und gefällt mir ausgezeichnet. Die Intellisencebox will bei mir aber noch nicht so recht. Sie bricht mit "Line 17 / GUIRegisterMsg($WM_COMMAND, 'MY_WM_COMMAND') / Variable used without declared" ab. Ich suche zur Zeit das include, wo diese Variable / Function definiert wird.

    Liebe Grüße,
    Reinhold.

  • Hi,
    benutz doch OrganizeIncludes von Xeno, das sucht dir die Inludes und setzt sie an den Anfag. Bei mir spuckt es folgende Includes aus:

    [autoit]

    #include <File.au3>
    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIListBox.au3>
    #include <Misc.au3>

    [/autoit]
  • Hallo liebe Gemeinde! *lol

    Das "Fahrtenschreiberskript" ist nun schon fast so, wie ich es mir vorstelle. Basierend auf der Arbeit von BugFix habe ich einige wenige Änderungen vorgenommen, um es meinen Bedürfnissen vollends anzupassen. (Klingt das zu hochtrabend?) Wie dem auch sei, ersteinmal möchte ich Euch allen - zuvorderst natürlich BugFix - für Eure Hilfe danken. Ohne Euch wäre aus der Idee nie etwas geworden.

    Die Änderungen betreffen hauptsächlich

    - die Anzahl der sichtbaren Zeilen im Eingabefenster (auf 16 reduziert, da auch nur 16 Zeilen im Abrechnungsblatt),
    - die Möglichkeit, (fast) leere Zeilen erzeugen zu können (Datum und Zeit kann ich nicht leer lassen),
    - das Hinterlegen der Auswahlmöglichkeiten
    - und das positionsgenaue Ausfüllen des Abrechnungsblattes

    (Der Button "Kilometertabelle" wird wohl wieder verschwinden, sollte ich nicht doch noch endlich herausfinden, wie ich eine zweite GUI schließen kann, ohne dass die erste (der Fahrtenschreiber) sich ebenfalls verabschiedet.)

    Falls jemand damit mal herumspielen möchte, das Skript (bzw. die Skripte, da je eines für Post, Zeitung, Werbung) und dessen / deren Abrechnungsbögen habe ich gezippt hochgeladen. Einfach alle Dateien in einen beliebigen Ordner entpacken und wie gewohnt starten.

    (Wenn man mehr als 16 Strecken in der Eingabemaske zusammenstellt und überträgt - was problemlos möglich ist - zerschießt man sich das Layout der betreffenden Excel-Tabelle. In dem Fall einfach neu aus dem Zip-File in den Ordner kopieren.)

    Mit lieben Grüßen und bestem Dank,
    Arioch!

    • Offizieller Beitrag

    Hallo,

    Schön, dass du uns Report erstattest, so macht helfen auch Spaß :).

    Zitat

    (Der Button "Kilometertabelle" wird wohl wieder verschwinden, sollte ich nicht doch noch endlich herausfinden, wie ich eine zweite GUI schließen kann, ohne dass die erste (der Fahrtenschreiber) sich ebenfalls verabschiedet.)

    Beide GUIs am Anfang erstellen und dann nur mit GUISetState wie gewünscht ein- und ausblenden. Es darf nur eine große Endlosschleife in deinem Skript geben, das kann man zusammenlegen. Im OnEventMode (der "normale") hilft GUIGetMsg(1), die Fenster auseinanderzuhalten, siehe Hilfe :).

    Schönen Tag dir,
    peethebee