Im Anhang nur mal ein Sample (noch ohne die Konvertierung Array>PDF + Kommentarfeld).
Sicherlich noch einige andere Anpassungen notwendig aber ich denke manchmal ist es einfacher einfach mal einen Ausgangspunkt, der nicht nur aus Text besteht, zu haben.
Hier der Code (die GUI sollte sich dynamisch anpassen wenn man die jeweiligen Konstanen ändert für die jeweiligen Bedürfnisse):
AutoIt
Opt('MustDeclareVars', 1)
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.16.0
Author: Moombas
Script Function:
Get data from a csv (*.dat) file put it into a Listview and save it as PDF
ToDo:
- Convert from Array to PDF as table and insert comment text
#ce ----------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <Array.au3>
#include <AutoItConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
;GUI
Global $fMain, $lvData, $eComment, $bSave, $bClose, $bReset, $bNext
Global Const $iMainWidth = 1024
Global Const $iMainHeight = 768
Global Const $iCommHeight = 200
Global Const $iBtnHeight = 40
Global Const $iBtnWidth = 100
Global Const $iBorder = 5
;Variables
Global $File, $FileName
Global $bSaved = False
Global Const $sInputFolder = @ScriptDir & '\In\'
Global Const $sOutputFolder = @ScriptDir & '\Out\'
Global Const $sBackupFolder = @ScriptDir & '\Backup\'
$FileName = FileFindNextFile(FileFindFirstFile($sInputFolder & '*.dat'))
_FileReadToArray($sInputFolder & $FileName, $File, $FRTA_NOCOUNT, ';')
If not IsArray($File) then
MsgBox($MB_OK+$MB_ICONERROR, 'Fehler', 'Keine Datei gefunden.')
Exit
Else
_GenerateGUI($File)
EndIf
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $bReset
_CreateListView($File)
Case $bNext
_NextFile()
Case $bSave
_DataToPDF()
_NextFile()
Case $bClose
_Exit()
EndSwitch
;~ sleep(100)
WEnd
Func _GenerateGUI($aFile)
Local Const $sTitle = $aFile[0][0]
$fMain = GUICreate($sTitle, $iMainWidth, $iMainHeight)
_CreateListView($aFile)
$eComment = GUICtrlCreateEdit('Insert comments here', $iBorder, $iMainHeight-(2*$iBorder)-$iCommHeight-$iBtnHeight, $iMainWidth-(2*$iBorder), $iCommHeight)
$bReset = GUICtrlCreateButton('Reset' , $iBorder , $iMainHeight-$iBorder-$iBtnHeight, $iBtnWidth, $iBtnHeight)
$bNext = GUICtrlCreateButton('Nächste' , (2*$iBorder)+$iBtnWidth , $iMainHeight-$iBorder-$iBtnHeight, $iBtnWidth, $iBtnHeight)
$bSave = GUICtrlCreateButton('Speichern', ($iMainWidth/2)-($iBtnWidth/2)-(2*$iBorder), $iMainHeight-$iBorder-$iBtnHeight, $iBtnWidth, $iBtnHeight)
$bClose = GUICtrlCreateButton('Beenden' , $iMainWidth-$iBorder-$iBtnWidth , $iMainHeight-$iBorder-$iBtnHeight, $iBtnWidth, $iBtnHeight)
GUISetState(@SW_HIDE, $bNext)
GUISetState(@SW_SHOW, $fMain)
EndFunc
Func _NextFile();Nimmt aktuell nur die erste gefundene Datei, Anpassungen notwendig, sofern durchgeklickt werden soll. Nach dem Speichern, wird hiermit die nächste Datei aufgerufen
If not $bSaved then
If MsgBox($MB_YESNO, 'Beenden ohne zu Speichern?', 'Wollen sie das Programm beenden ohne zu speichern?' & @CRLF & _
'Mögliche Änderungen gehen sonst verloren.') = $IDYES Then Return
EndIf
$FileName = FileFindNextFile(FileFindFirstFile($sInputFolder & '*.dat'))
_FileReadToArray($sInputFolder & $FileName, $File, $FRTA_NOCOUNT, ';'); Kann gegen eine Funktion ausgetauscht werden um z.B. alle *.? Dateien in einem "Inputordner" o.ä. zu verarbeiten.
If not IsArray($File) then
MsgBox($MB_OK+$MB_ICONERROR, 'Fehler', 'Keine weitere Datei gefunden.')
Exit
Else
_CreateListView($File)
EndIf
EndFunc
Func _CreateListView($aFile)
Local Const $iRows = Ubound($aFile, $UBOUND_Rows)-1
Local Const $iCols = Ubound($aFile, $UBOUND_COLUMNS)-1
Local Const $sTitle = $aFile[0][0]
$aFile[0][0] = ''
WinSetTitle($fMain, '', $sTitle)
_GUICtrlListView_Destroy($lvData)
$lvData = GUICtrlCreateListView("", $iBorder, $iBorder, $iMainWidth-(2*$iBorder), $iMainHeight-(4*$iBorder)-$iCommHeight-$iBtnHeight, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetExtendedListViewStyle($lvData, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
For $iCol = 0 To $iCols
_GUICtrlListView_AddColumn($lvData, $aFile[0][$iCol], 150)
Next
For $iRow = 0 To $iRows
_GUICtrlListView_AddItem($lvData, $aFile[$iRow][0], $iRow)
For $iCol = 1 to $iCols
_GUICtrlListView_AddSubItem($lvData, $iRow, $aFile[$iRow][$iCol], $iCol)
Next
Next
GUICtrlSetData($eComment, 'Insert comments here')
$bSaved = False
Endfunc
Func _DataToPDF()
Local $aData = _GUICtrlListView_CreateArray($lvData)
_ArrayDelete($aData, 0)
;PDF Code comes here
;When ready
FileMove($sInputFolder & $FileName, $sBackupFolder & WinGetTitle($fMain) & '_' & $FileName, $FC_OVERWRITE + $FC_CREATEPATH)
$bSaved = True
EndFunc
Func _Exit()
If $bSaved then
Exit
Else
If MsgBox($MB_YESNO, 'Beenden ohne zu Speichern?', 'Wollen sie das Programm beenden ohne zu speichern?' & @CRLF & _
'Mögliche Änderungen gehen sonst verloren.') = $IDYES Then Exit
EndIf
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlListView_CreateArray
; Description ...: Creates a 2-dimensional array from a listview.
; Syntax ........: _GUICtrlListView_CreateArray($hListView[, $sDelimeter = '|'])
; Parameters ....: $hListView - Control ID/Handle to the control
; $sDelimeter - [optional] One or more characters to use as delimiters (case sensitive). Default is '|'.
; Return values .: Success - The array returned is two-dimensional and is made up of the following:
; $aArray[0][0] = Number of rows
; $aArray[0][1] = Number of columns
; $aArray[0][2] = Delimited string of the column name(s) e.g. Column 1|Column 2|Column 3|Column nth
; $aArray[1][0] = 1st row, 1st column
; $aArray[1][1] = 1st row, 2nd column
; $aArray[1][2] = 1st row, 3rd column
; $aArray[n][0] = nth row, 1st column
; $aArray[n][1] = nth row, 2nd column
; $aArray[n][2] = nth row, 3rd column
; Author ........: guinness
; Remarks .......: GUICtrlListView.au3 should be included.
; Example .......: Yes
; ===============================================================================================================================
Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|')
Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView)
If $iColumnCount < 3 Then
$iDim = 3 - $iColumnCount
EndIf
If $sDelimeter = Default Then
$sDelimeter = '|'
EndIf
Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
For $i = 0 To $iColumnCount - 1
$aColumns = _GUICtrlListView_GetColumn($hListView, $i)
$aReturn[0][2] &= $aColumns[5] & $sDelimeter
Next
$aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
For $i = 0 To $iItemCount - 1
For $j = 0 To $iColumnCount - 1
$aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
Next
Next
Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc ;==>_GUICtrlListView_CreateArray
Alles anzeigen