Exel Daten (.xls / .xlsx) in .txt Daten umwandeln

    • Offizieller Beitrag

    Ah okay, hier noch mal schnell was angepasst.

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <Excel.au3>
    #include <File.au3>

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

    Opt('MustDeclareVars', 1)

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

    Local $loadPath_excel_format = @ScriptDir
    Local $outputPath_txt_format = @ScriptDir & "\Output"
    Local $archivPath_txt_format = @ScriptDir & "\Archiv"

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

    ;~ Local $loadPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Input"
    ;~ Local $outputPath_txt_format = "C:\Users\dacohelpdesk\Desktop\test\Output"
    ;~ Local $archivPath_txt_format = "C:\Users\dacohelpdesk\Desktop\test\Archiv"

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

    Local $oExcel = 0

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

    Local $excelFile_A = _FileListToArray($loadPath_excel_format, '*.xls', 1)
    If @error Then ConsoleWrite('_FileListToArray : ' & @error & @LF)

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

    ConsoleWrite('Dateien: ' & @CRLF & _ArrayToString($excelFile_A) & @LF)

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

    For $i = 1 To UBound($excelFile_A) - 1
    $oExcel = _ExcelBookOpen($loadPath_excel_format & '\' & $excelFile_A[$i], 0)
    If @error Then ConsoleWrite('_ExcelBookOpen : ' & @error & ' ' & $loadPath_excel_format & '\' & $excelFile_A[$i] & @LF)

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

    _ExcelBookSaveAs($oExcel, $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1), "txt")
    If @error Then ConsoleWrite('_ExcelBookSaveAs : ' & @error & @LF)

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

    _ExcelBookClose($oExcel, 1, 0)
    If @error Then ConsoleWrite('_ExcelBookClose : ' & @error & @LF)

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

    If FileExists($outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt') = 1 Then
    If FileMove($loadPath_excel_format & '\' & $excelFile_A[$i], $archivPath_txt_format, 9) Then ConsoleWrite('+>' & $loadPath_excel_format & '\' & $excelFile_A[$i] & ' erfolgreich archiviert' & @LF)
    Else
    ConsoleWrite('File not found : ' & $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt' & @LF)
    EndIf
    Next

    [/autoit]
  • Jetzt kommt das:

    Code
    >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\dacohelpdesk\Desktop\test\Exel converter - Kopie.au3" /UserParams    
    +>15:10:56 Starting AutoIt3Wrapper v.2.1.0.33    Environment(Language:0407  Keyboard:00000807  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
    >Running AU3Check (1.54.22.0)  from:C:\Program Files (x86)\AutoIt3
    +>15:10:56 AU3Check ended.rc:0
    >Running:(3.3.8.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\dacohelpdesk\Desktop\test\Exel converter - Kopie.au3"    
    --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
    _FileListToArray : 4
    Dateien: 
    +>15:10:56 AutoIT3.exe ended.rc:0
    >Exit code: 0    Time: 1.021
  • Da ist doch eine Datei! ;) Also nochmal zum Verständniss:

    Exel Daten kommen in Input rein. Werden duch den Script umgewandelt und abgepeichert im Output als Datendateien. Dann soll es die Daten von Input und Output vergleichen wenn es den gleichen Namen hat dann die Datei aus dem Input (Excel) verschieben ins Archiv. Hoffe das es jetzt klar ist :D

    • Offizieller Beitrag

    Genau!
    Siehe hier:

    Local $inputPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Input" <-- da deine Excel
    Local $outputPath_txt_format = "C:\Users\dacohelpdesk\Desktop\test\Output" <-- da kommen die umgewandelten txt hin
    Local $archivPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Archiv" <-- da landen die Excel wenn es geklappt hat

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <Excel.au3>
    #include <File.au3>

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

    Opt('MustDeclareVars', 1)

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

    ;~ Local $inputPath_excel_format = @ScriptDir
    ;~ Local $outputPath_txt_format = @ScriptDir & "\Output"
    ;~ Local $archivPath_excel_format = @ScriptDir & "\Archiv"

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

    Local $inputPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Input"
    Local $outputPath_txt_format = "C:\Users\dacohelpdesk\Desktop\test\Output"
    Local $archivPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Archiv"

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

    Local $oExcel = 0

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

    Local $excelFile_A = _FileListToArray($inputPath_excel_format, '*.xls', 1)
    If @error Then ConsoleWrite('_FileListToArray : ' & @error & @LF)

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

    ConsoleWrite('Dateien: ' & @CRLF & _ArrayToString($excelFile_A) & @LF)

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

    For $i = 1 To UBound($excelFile_A) - 1
    $oExcel = _ExcelBookOpen($inputPath_excel_format & '\' & $excelFile_A[$i], 0)
    If @error Then ConsoleWrite('_ExcelBookOpen : ' & @error & ' ' & $inputPath_excel_format & '\' & $excelFile_A[$i] & @LF)

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

    _ExcelBookSaveAs($oExcel, $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1), "txt")
    If @error Then ConsoleWrite('_ExcelBookSaveAs : ' & @error & @LF)

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

    _ExcelBookClose($oExcel, 1, 0)
    If @error Then ConsoleWrite('_ExcelBookClose : ' & @error & @LF)

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

    If FileExists($outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt') = 1 Then
    If FileMove($inputPath_excel_format & '\' & $excelFile_A[$i], $archivPath_excel_format, 9) Then ConsoleWrite('+>' & $inputPath_excel_format & '\' & $excelFile_A[$i] & ' erfolgreich archiviert' & @LF)
    Else
    ConsoleWrite('File not found : ' & $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt' & @LF)
    EndIf
    Next

    [/autoit]
  • Ich habe gerade gesehen das du im Output Ordner nach .txt Dateien suchst. Klar kann das ganze nicht gehen da mir ja komischerweise immer noch die Daten als Datendateien gespeichert werden also Namederdatei.xlsx --> Namederdatei ohne .txt.

  • Code
    >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\dacohelpdesk\Desktop\test\Exel converter - Kopie.au3" /UserParams 
    +>16:17:18 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0407 Keyboard:00000807 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64) 
    >Running AU3Check (1.54.22.0) from:C:\Program Files (x86)\AutoIt3 
    +>16:17:18 AU3Check ended.rc:0 
    >Running:(3.3.8.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\dacohelpdesk\Desktop\test\Exel converter - Kopie.au3" 
    --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop 
    _FileListToArray : 4 
    Dateien: 
    +>16:17:18 AutoIT3.exe ended.rc:0 
    >Exit code: 0 Time: 1.986

    Die Datendatei wird in Output geschrieben und ins Archiv wird nichts verschoben.

    • Offizieller Beitrag

    Ganz ehrlich, du musst dir das schon ein bisschen selbst angucken und mitdenken.
    Das Log sagt eindeutig, dass keine Exceldatei gefunden wurde in deinem Inputordner.

    _FileListToArray


    @Error:
    1 = Path not found or invalid
    2 = Invalid $sFilter
    3 = Invalid $iFlag
    4 = No File(s) Found

  • EDIT: Das Problem hat sich gelöst. Vielen Dank an Xenobiologist der meine Dummheit ertragen hat :D und mir so zu einem funktionierenden Programm verholfen hat.

    Vielen Dank auch an alle die mir Tipps und Tricks mitgegeben haben. Ihr seid die besten :thumbup:

    LG Ru642

    Hier der Script:

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <Excel.au3>
    #include <File.au3>
    Opt('MustDeclareVars', 1)
    ;~ Local $inputPath_excel_format = @ScriptDir
    ;~ Local $outputPath_txt_format = @ScriptDir & "\Output"
    ;~ Local $archivPath_excel_format = @ScriptDir & "\Archiv"
    Local $inputPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Input"
    Local $outputPath_txt_format = "C:\Users\dacohelpdesk\Desktop\test\Output"
    Local $archivPath_excel_format = "C:\Users\dacohelpdesk\Desktop\test\Archiv"

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

    Local $oExcel = 0
    Local $excelFile_A = _FileListToArray($inputPath_excel_format, '*.xls', 1)
    If @error Then ConsoleWrite('_FileListToArray : ' & @error & @LF)
    ConsoleWrite('Dateien: ' & @CRLF & _ArrayToString($excelFile_A) & @LF)
    For $i = 1 To UBound($excelFile_A) - 1
    $oExcel = _ExcelBookOpen($inputPath_excel_format & '\' & $excelFile_A[$i], 0)
    If @error Then ConsoleWrite('_ExcelBookOpen : ' & @error & ' ' & $inputPath_excel_format & '\' & $excelFile_A[$i] & @LF)
    _ExcelBookSaveAs($oExcel, $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1), "txt")
    If @error Then ConsoleWrite('_ExcelBookSaveAs : ' & @error & @LF)
    _ExcelBookClose($oExcel, 1, 0)
    If @error Then ConsoleWrite('_ExcelBookClose : ' & @error & @LF)
    If FileExists($outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt') = 1 Then ; das hatte gefehlt (& '.txt')
    If FileMove($inputPath_excel_format & '\' & $excelFile_A[$i], $archivPath_excel_format, 9) Then ConsoleWrite('+>' & $inputPath_excel_format & '\' & $excelFile_A[$i] & ' erfolgreich archiviert' & @LF)
    Else
    ConsoleWrite('File not found : ' & $outputPath_txt_format & '\' & StringLeft($excelFile_A[$i], StringInStr($excelFile_A[$i], '.', Default, -1) - 1) & '.txt' & @LF)
    EndIf
    Next

    [/autoit]

     Kann geclosed werden

    3 Mal editiert, zuletzt von ru642 (16. Januar 2013 um 10:57)

  • Kann geclosed werden


    Geclosed werden hier nur Themen die gegen die Forenregeln verstossen. Du solltest es allerdings auf gelöst setzen.
    Dazu einfach den Eröffnungsbeitrag bearbeiten und den Präfix (nähe) Überschrift auf gelöst setzen und absenden.

    danke autoBert