Exceldatenblatterstellung per GUI-Combo die Zweite

  • Tach zusammen! :)

    Nach ein wenig PC- und AutoIt-Abstinenz würde ich gern noch einmal meine Datenblatterstellung aufgreifen.

    Durch einen kleinen Eingriff habe ich es geschafft, dass mir im Datenblatt bereits "beschriebene" Zeilen - also schon erstellte Touren - erhalten bleiben. Nicht sehr schön, aber es funktioniert. (Sinn des Ganzen war es, dass ich nicht alle Touren auf einmal eintragen muß. So kann ich jetzt, sagen wir, einmal pro Woche 5 Minuten aufwenden, anstatt einmal im Monat alle Zettel zusammen zu suchen.) Gelungen ist es mir dadurch, dass ich die Abfrage "Besitzt eine Zeile schon Inhalt?" von anfangs 9 Zeilen auf die ersten 25 Zeilen ausgedehnt habe.

    So sah es aus:

    Spoiler anzeigen
    [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 = "."

    $oExcel.Activesheet.Range("A2").Value = "."

    $oExcel.Activesheet.Range("A3").Value = "."

    $oExcel.Activesheet.Range("A4").Value = "."

    $oExcel.Activesheet.Range("A4").Value = "."

    $oExcel.Activesheet.Range("A5").Value = "."

    $oExcel.Activesheet.Range("A6").Value = "."

    $oExcel.Activesheet.Range("A7").Value = "."

    $oExcel.Activesheet.Range("A8").Value = "."

    $oExcel.Activesheet.Range("A9").Value = "."

    _ExcelBookSaveAs($oExcel, $ExelPath)
    _ExcelBookClose($oExcel)
    EndIf
    $oExcel = _ExcelBookOpen($ExelPath, 0)
    Local $Row = _ExcelBookGetWidth($oExcel, 2) +1 ;Reihen beginnen ab Zeile 2!
    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 = ""
    $oExcel.Activesheet.Range("H" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 6)
    Next
    _GUICtrlListView_DeleteAllItems($hListView)
    _ExcelBookClose($oExcel)
    EndFunc

    [/autoit]

    Und so sieht es jetzt aus:

    Spoiler anzeigen
    [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 = "."

    $oExcel.Activesheet.Range("A2").Value = "."

    $oExcel.Activesheet.Range("A3").Value = "."

    $oExcel.Activesheet.Range("A4").Value = "."

    $oExcel.Activesheet.Range("A4").Value = "."

    $oExcel.Activesheet.Range("A5").Value = "."

    $oExcel.Activesheet.Range("A6").Value = "."

    $oExcel.Activesheet.Range("A7").Value = "."

    $oExcel.Activesheet.Range("A8").Value = "."

    $oExcel.Activesheet.Range("A9").Value = "."

    $oExcel.Activesheet.Range("A10").Value = "."

    $oExcel.Activesheet.Range("A11").Value = "."

    $oExcel.Activesheet.Range("A12").Value = "."

    $oExcel.Activesheet.Range("A13").Value = "."

    $oExcel.Activesheet.Range("A14").Value = "."

    $oExcel.Activesheet.Range("A15").Value = "."

    $oExcel.Activesheet.Range("A16").Value = "."

    $oExcel.Activesheet.Range("A17").Value = "."

    $oExcel.Activesheet.Range("A18").Value = "."

    $oExcel.Activesheet.Range("A19").Value = "."

    $oExcel.Activesheet.Range("A20").Value = "."

    $oExcel.Activesheet.Range("A21").Value = "."

    $oExcel.Activesheet.Range("A22").Value = "."

    $oExcel.Activesheet.Range("A23").Value = "."

    $oExcel.Activesheet.Range("A24").Value = "."

    $oExcel.Activesheet.Range("A25").Value = "."

    _ExcelBookSaveAs($oExcel, $ExelPath)
    _ExcelBookClose($oExcel)
    EndIf
    $oExcel = _ExcelBookOpen($ExelPath, 0)
    Local $Row = _ExcelBookGetWidth($oExcel, 2) +1 ;Reihen beginnen ab Zeile 2!
    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 = ""
    $oExcel.Activesheet.Range("H" & $Row+$i).Value = _GUICtrlListView_GetItemText($hListView, $i, 6)
    Next
    _GUICtrlListView_DeleteAllItems($hListView)
    _ExcelBookClose($oExcel)
    EndFunc

    [/autoit]

    Hilft schon mal weiter... könnte man aber etwas verbessern. Ich würde gern eine Abfrage einbauen, die Folgendes überprüft:

    - Sind alle Zeilen bis Zeile 25 einschließlich beschrieben? ; nach Zeile 25 ist das Datenblatt voll
    - Wenn nein, schreibe eine neue Zeile in das Datenblatt
    - Sind jetzt alle Zeilen bis Zeile 25 einschließlich beschrieben?
    - Wenn ja, öffne MsgBox, Text: "Datenblatt voll, bitte speichern und neues erstellen"
    - wenn Klick auf OK, Datenblatt öffnen zum Speichern

    Wenn ich auch noch nicht weiß, wo genau ich diese If-Abfrage einbinden muß, nehme ich an, dieses durch "rumprobieren" herauszufinden. Das Problem, an dem ich mir die Zähne ausbeißen werde, ist "Wie schaffe ich es, das die GUI nach einigen geschriebenen Zeilen (sobald das Datenblatt voll ist und ich es erst speichern muß) den Schreibvorgang unterbricht und wartet, bis ich das Ok zum Weiterschreiben gebe?"

    Irgendwelche Ideen? Ansätze? Kommentare?

    Wie immer in der Hoffnung: "Hier werden Sie geholfen!",
    mit lieben Grüßen,
    Reinhold.

  • Kennst du die Excel-UDF aus der aktuellen Beta schon? Es gibt dort interessante Funktionen die dir das Leben erleichtern könnten.

    Spoiler anzeigen


    _ExcelBookAttach Attach to the first existing instance of Microsoft Excel where the search string matches based on the selected mode.

    _ExcelBookClose Closes the active workbook and removes the specified Excel object.

    _ExcelBookNew Creates new workbook and returns its object identifier.

    _ExcelBookOpen Opens an existing workbook and returns its object identifier.

    _ExcelBookSave Saves the active workbook of the specified Excel object.

    _ExcelBookSaveAs Saves the active workbook of the specified Excel object with a new filename and/or type.

    _ExcelColumnDelete Delete a number of columns from the active worksheet.

    _ExcelColumnInsert Insert a number of columns into the active worksheet.

    _ExcelFontSetProperties Set the bold, italic, and underline font properties of a range in an Excel object.

    _ExcelHorizontalAlignSet Set the horizontal alignment of each cell in a range.

    _ExcelHyperlinkInsert Inserts a hyperlink into the active page.

    _ExcelNumberFormat Applies the specified formatting to the cells in the specified R1C1 Range.

    _ExcelReadArray Create an array from a row or column of the active worksheet.

    _ExcelReadCell Read information from the active worksheet of the specified Excel object.

    _ExcelReadSheetToArray Create a 2D array from the rows/columns of the active worksheet.

    _ExcelRowDelete Delete a number of rows from the active worksheet.

    _ExcelRowInsert Insert a number of rows into the active worksheet.

    _ExcelSheetActivate Activate the specified sheet by string name or by number.

    _ExcelSheetAddNew Add new sheet to workbook - optionally with a name.

    _ExcelSheetDelete Delete the specified sheet by string name or by number.

    _ExcelSheetList Return a list of all sheets in workbook, by name, as an array.

    _ExcelSheetMove Move the specified sheet before another specified sheet.

    _ExcelSheetNameGet Return the name of the active sheet.

    _ExcelSheetNameSet Set the name of the active sheet.

    _ExcelWriteArray Write an array to a row or column on the active worksheet of the specified Excel object.

    _ExcelWriteCell Write information to a cell on the active worksheet of the specified Excel object.

    _ExcelWriteFormula Write a formula to a cell on the active worksheet of the specified Excel object.

    _ExcelWriteSheetFromArray Writes a 2D array to the active worksheet