Hallo Leute,
ich habe eine csv Datei. Diese würde ich gerne auslesen, und die dort ausgelesenen Werte Variablen zuordnen und diese dann wiederum in eine neue Datei wegschreiben.
Also so:
CSV Datei:
name; ort; datum
schmidt; berlin; 22.1.2005
müller; nürnberg; 12.1.1987
Es gibt 3 Variablen, also:
Feld1
Feld2
Feld3
Lese aus csv Datei Line1, separiere jedes Wort, die mit ; getrennt sind
Schreibe folgendes in die neue Datei (folgendes als Text in die neue Datei, nicht nur den Inhalt der Variablen):
$feld1 = schmidt
$feld2 = berlin
$feld3 = 22.1.2005
nimm nächste Zeile
Schreibe weiter, beginne wieder mit
$feld1 = müller
$feld2 = nürnberg
$feld3 = 12.1.1987
u.s.w., bis csv Datei zu Ende
Bisher bin ich soweit gekommen, dass ich alles aus der csv Datei auslese, und dies in die neue Datei für jedes separates Wort eine neue Zeile schreibe.
Was mir fehlt, ist dass Schreiben meiner Variablennamen + die dahinter ausgelesenen Werte aus der CSV Datei; im Moment wird die neue Datei zwar geschrieben, jedoch nicht so, wie ich es erwarte, also Variable1 = Wert1 aus Zeile 1: Variable2 = Wert2 aus Zeile 1; u.s.w.
Kann mir bitte jemand einen Hinweis geben, wo mein Fehler liegt?
Joe
; Script zum Auslesen von Excel Tabelle und Erstellung eines eigentständigen Scripts
;Dieses wiederum enthält dann Code zum Anzeigen einer GUI sowie pro ausgelesenem Drucker einen Button mit Bild
; Deutsche Version
;Notwendige Consanten/Variablen holen
#Include <Constants.au3>
#include <GUIConstantsEx.au3>
#NoTrayIcon
;Variablen im gesamten Programm verfügbar machen
Local $PrnDisplayName, $ndprxxx_01, $ndprxxx_02, $PrnInfPath, $PrnInfInternalName, $reg_printer_ports, $reg_ports, $RegPpPDN, $strLogFile, $Location
Local $IsWhat, $PicPath
Local $testvar
Local $wr_PrnDisplayName
Local $wr_ndprxxx_01
Local $wr_ndprxxx_02
Local $wr_PrnInfPath
Local $wr_PrnInfInternalName
Local $wr_reg_printer_ports
Local $wr_reg_ports
Local $wr_RegPpPDN
Local $wr_strLogFile
Local $wr_Location
Local $wr_IsWhat
Local $wr_PicPath
;Öffnen einer Datei zum Auslesen derselber und reinschreiben in Variablen
GUICreate("Printeradministration", 630, 510)
GUISetState (@SW_SHOW)
#region --- ScriptWriter generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
$h_MapFile = FileOpen("mappe1.csv", 0)
$output = FileOpen("dynamic_script.au3",2)
$i_Counter = 0
;Lesen der Vorlagendatei für die Erstellung dynamisches Script
$file = FileOpen("vorlage.au3",0)
$chars = FileRead($file)
;Gelesene Daten in dynamische Datei schreiben
FileWrite($output, $chars)
;Felder definieren
Dim $filefields[12]
$filefields[0] = $PrnDisplayName
$filefields[1] = $ndprxxx_01
$filefields[2] = $ndprxxx_02
$filefields[3] = $PrnInfPath
$filefields[4] = $PrnInfInternalName
$filefields[5] = $reg_printer_ports
$filefields[6] = $reg_ports
$filefields[7] = $RegPpPDN
$filefields[8] = $strLogFile
$filefields[9] = $Location
$filefields[10] = $IsWhat
$filefields[11] = $PicPath
;Zeile für Zeile lesen, da jede Zeile 1 Drucker darstellt
While 1
$i_Counter = $i_Counter + 1
$scanned_line = FileReadLine($h_MapFile, $i_Counter) ; Gesamte Zeile lesen
If @error Then
MsgBox(0, "Error", "Finished")
ExitLoop
EndIf
;Zeile wiederum auftrennen, da Werte mit ";" abgetrennt
$separate_words = StringSplit($scanned_line, ";")
$s_MsgBox = ''
For $i = 1 to 12
$s_MsgBox = $s_MsgBox & $filefields[$i-1] & $separate_words[$i] & @LF
FileWriteLine($output,"$PrnDisplayName = " & $s_MsgBox)
FileWriteLine($output,"$ndprxxx_01 = " & $s_MsgBox)
FileWriteLine($output,"$ndprxxx_02 = " & $s_MsgBox)
FileWriteLine($output,"$PrnInfPath = " & $s_MsgBox)
FileWriteLine($output,"$PrnInfInternalName = " & $s_MsgBox)
FileWriteLine($output,"$reg_printer_ports = " & $s_MsgBox)
FileWriteLine($output,"$reg_ports = " & $s_MsgBox)
FileWriteLine($output,"$RegPpPDN = " & $s_MsgBox)
FileWriteLine($output,"$strLogFile = " & $s_MsgBox)
FileWriteLine($output,"$Location = " & $s_MsgBox)
FileWriteLine($output,"$IsWhat = " & $s_MsgBox)
FileWriteLine($output,"$PicPath = " & $s_MsgBox)
Next
;MsgBox(0, 'Map #' & $i_Counter, $s_MsgBox)
WEnd
FileClose($h_MapFile)
FileClose($file)
FileClose($output)
Alles anzeigen
Hier ein Auszug des derzeit erzeugten Scripts:
$PrnDisplayName = PrnDisplayName
$ndprxxx_01 = PrnDisplayName
$ndprxxx_02 = PrnDisplayName
$PrnInfPath = PrnDisplayName
$PrnInfInternalName = PrnDisplayName
$reg_printer_ports = PrnDisplayName
$reg_ports = PrnDisplayName
$RegPpPDN = PrnDisplayName
$strLogFile = PrnDisplayName
$Location = PrnDisplayName
$IsWhat = PrnDisplayName
$PicPath = PrnDisplayName
$PrnDisplayName = PrnDisplayName
ndprxxx_01
$ndprxxx_01 = PrnDisplayName
ndprxxx_01
$ndprxxx_02 = PrnDisplayName
ndprxxx_01
$PrnInfPath = PrnDisplayName
ndprxxx_01
$PrnInfInternalName = PrnDisplayName
ndprxxx_01
$reg_printer_ports = PrnDisplayName
ndprxxx_01
$reg_ports = PrnDisplayName
ndprxxx_01
$RegPpPDN = PrnDisplayName
ndprxxx_01
$strLogFile = PrnDisplayName
ndprxxx_01
$Location = PrnDisplayName
ndprxxx_01
$IsWhat = PrnDisplayName
ndprxxx_01
$PicPath = PrnDisplayName
ndprxxx_01
$PrnDisplayName = PrnDisplayName
Alles anzeigen