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
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
Und so sieht es jetzt aus:
Spoiler anzeigen
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
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.