Ich habe das Tabellenformat in der *.dat nochmal an das angepasst, was du gepostet hast, er nimmt den Titel nun aus dem Dateinamen anstatt der Tabelle (passt sonst nicht) und ein erster Entwurf für die PDF-Erstellung ist drin, müsstest du Testen.
Was noch fehlen würde wäre:
- Prüfung ob alles auf eine Seite passt und ggf. nächste Seite erzeugen.
- Anpassung der Schrift (aktuell sehen die Tabelleneinträge aus wie bold und die Überschrift nicht, irgendwie falsch herum, hab aber da die Lösung nicht gefunden)
- Kopfzeile und Fußzeile (das sollte relativ einfach machbar sein)
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:
- Prüfung ob alles auf eine Seite passt und ggf. nächste Seite erzeugen.
- Anpassung der Schrift
- Kopfzeile und Fußzeile
#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>
#include "MPDF_UDF.au3"
;GUI
Global $fMain, $lvData, $eComment, $bSave, $bClose, $bReset, $bNext, $iTableHigh
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
_FileReadToArray($sInputFolder & $FileName, $File, $FRTA_NOCOUNT, ';')
_CreateListView($File)
Case $bNext
_NextFile()
Case $bSave
_DataToPDF()
_NextFile()
Case $bClose
_Exit()
EndSwitch
;~ sleep(100)
WEnd
Func _GenerateGUI($aFile)
Local Const $sTitle = Stringsplit($FileName, '.')[1]
$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 = Stringsplit($FileName, '.')[1]
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)
Local Const $sTitle = Stringsplit($FileName, '.')[1]
Local Const $iBorder = 2
Local Const $bTest = True
Local Const $iRows = Ubound($aData, $UBOUND_Rows)-1
Local Const $iCols = Ubound($aData, $UBOUND_COLUMNS)-1
_ArrayDelete($aData, 0)
;PDF Code comes here
;set the properties for the pdf
_SetTitle($sTitle)
_SetSubject('')
_SetKeywords("pdf, data, sqllite")
_OpenAfter($bTest);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("CUSTOM",841.890, 595.276); A4 landscape
_SetZoomMode($PDF_ZOOM_FULLPAGE)
_SetOrientation($PDF_ORIENTATION_LANDSCAPE)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)
;initialize the pdf
_InitPDF($sOutputFolder & WinGetTitle($fMain) & '_' & Stringsplit($FileName, '.')[1] & '.pdf')
;=== load used font(s) ===
;fonts: Garamond
_LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD)
_LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC)
_LoadFontTT("_Calibri" , $PDF_FONT_CALIBRI)
;begin page
_BeginPage()
_InsertTable($aData, $iBorder, _GetPageHeight()/_GetUnit()-2-(0.8*$iRows) , 0, 0.8*$iRows, $iCols, $iRows)
_SetTextRenderingMode(1)
_InsertRenderedText((_GetPageWidth()/_GetUnit())/2, _GetPageHeight()/_GetUnit()-1.5 , $sTitle , "_Calibri", 16, 100, $PDF_ALIGN_CENTER, 0x000000, 0x000000)
_InsertRenderedText($iBorder , _GetPageHeight()/_GetUnit()-$iTableHigh-$iBorder-1, GUICtrlRead($eComment), '_Calibri', 12, 100, $PDF_ALIGN_LEFT , 0x000000, 0x000000)
_SetTextRenderingMode(0)
_EndPage()
;write the buffer to disk
_ClosePDFFile()
;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
Func _InsertTable($aData, $iX, $iY, $iW = 0, $iH = 0, $iCols = 0, $iRows = 0, $lTxtColor = 0x000000, $lBorderColor = 0xdddddd)
Local $lScale, $sLength, $sText, $iColW, $iRowH, $lRGB = 0xffffff
Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1)
Local $iPgH = Round(_GetPageHeight() /_GetUnit() , 1)
If $iW = 0 Then $iW = $iPgW - $iX - 2
If $iH = 0 Then $iH = $iPgH - $iY - 2
$iTableHigh = $iH
_SetColourStroke($lBorderColor)
_Draw_Rectangle($iX, $iY, $iW, $iH, $PDF_STYLE_STROKED, 0, 0xffffff, 0.01)
_SetColourStroke(0)
$iColW = $iW / $iCols
$iRowH = $iH / $iRows
For $i = 0 To $iRows - 1
For $j = 0 To $iCols - 1
;~ If $i = 0 Then
;~ $lRGB = 0xfefefe
;~ Else
;~ $lRGB = 0xefefef
;~ EndIf
_SetColourStroke($lBorderColor)
_Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lRGB, 0.01)
_SetColourStroke(0)
$sText = $aData[$i][$j]
If $sText = '' then $sText = ' '
$sLength = Round(_GetTextLength($sText, "_Calibri", 8), 1)
$lScale = Ceiling(0.75 * $iColW * 100 / $sLength)
_SetColourFill($lTxtColor)
_SetTextHorizontalScaling($lScale)
_DrawText($iX + $j * $iColW + $iColW / 10, $iY + $iH - ($i + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 8, $PDF_ALIGN_LEFT, 0)
_SetTextHorizontalScaling(100)
_SetColourFill(0)
Next
Next
EndFunc ;==>_InsertTable
; #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