Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Zeile oder Datensatz automatisch auslesen und in eine separate Datei abspeichern

Empfohlene Antworten

Veröffentlicht

Hallo,

hat jemand vielleicht eine Idee, habe ein kleines Problem.

ich habe eine Exceldatei. Diese Exceldatei beinhaltet n Zeilen.

Ich möchte nun jede Zeile lesen und in einer separaten Datei abspeichern.

Dabei soll der Dateiname auch automatisch generiert werden.

Dankeschön

Programmiert habe ich noch nichts, meine bisherige Idee sieht aber so aus:

1. Excel Datei als csv-Datei abspeichern

2. csv datei in ein zweidimensionales array speichern (a [n][m] )

3. zeile 1 auslesen, also a[0][0] bis a[0][m] und in eine datei abspeichern

Punkt drei solange wiederholen bis es keinen keine zeile mehr gibt.

ich hab mal bei autoit nachgeschaut

punkt zwei kann man damit realisieren.

punkt drei wird bisschen problematisch, da es nur ein befehl gibt wo man etwas in eine ini datei reischreiben kann (sprich :IniWrite(...) )

ich möchte aber in eine txt datei schreiben

Ich glaub du brauchst keine Arrays.

Hier mal ein bisschen Perlpseudocode der dir vllt. mit der möglichen Vorgehensweise weiterhilft.

 

$i=0;

open(FH, '<', "input.txt") or die $!;

while $line (<FH>)

{

    open(FH2, '>', "output-$i.txt") or die $!; 

    print FH2 $line;

    close FH2;

    $i++;

}

close FH;

Syntaxtipps für autoit hat dir robotto7831a ja gegeben.

Bearbeitet von bigvic

Mit PHP könnte man es auch so ähnlich lösen:


$inhalt = file("C:\blub.csv");
$zaehler = 0;

foreach($inhalt as $aktuelle_zeile){

$neue_datei = fopen("C:\blub" . $zaehler . ".txt", "w");

fwrite($neue_datei, $aktuelle_zeile);

$zaehler++;
}
[/PHP]

Gruß

Hauke

#include <File.au3>

; CSV Datei wird in ein array eingelesen

; --------------------------------------

Dim $arCSV

$csvFile = "test.csv"

_FileReadToArray ( $csvFile , $arCSV )

For $i = 1 To $arCSV[0]

$arCSV[$i] = StringSplit($arCSV[$i], ";")

Next

For $j = 1 To $arCSV[0]

$x = $arCSV[$j]

MsgBox(0,'', 'Anzahl dert Elemente von $arCSV[3]: ' & $x[5])

; Dateiname wird erzeugt

;-----------------------

$tag = @MDAY

$monat = @MON

$jahr = @YEAR

$std = @HOUR

$min = @MIN

$sek = @SEC

$bs = "-"

$Datum = $tag & $bs & $monat & $bs & $jahr & $bs & $std & $bs & $min & $bs & $sek

$dbegin = "descr"

$dendung = ".txt"

$dname = $dbegin & $Datum & $dendung

; Datei wird erzeugt

; ------------------

_FileCreate($dname)

; Erzeugte Datei wird geöffnet und Stellen aus der 1. Datei werden

; hinzugefügt

; ---------------------------------------------------------------

$file = FileOpen( $dname , 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWriteLine($file, "Line1")

FileWriteLine($file, "Line2" & @CRLF)

FileWriteLine($file, $x[5] )

FileClose($file)

Next

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.