HowTo: Unterstützung für beliebige csv-Formate
#bankstatement #howto
Am Beispiel der neuen csv
-Formatdatei csv-standard-bank-na.def
möchte ich hier mal hoffentlich allgemeinverständlich erklären, wie man mehr oder wenig beliebige csv
-Formate unterstützen kann. Nimm einfach eine der existierenden Dateien und passe sie entsprechend an!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
\renewcommand*\STM@JK@dbkeys{ValueDate,PostingDate,Reference,Narrative,Amount,Balance}% \renewcommand*\STM@JK@DTLforeach% {% \DTLforeach{\STM@JK@dbname}% {\postingdate=PostingDate,\valuedate=ValueDate,\reference=Reference,\narrative=Narrative,\amount=Amount,\balance=Balance}% {% \parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &% \parbox[t]{\STM@JK@referencewidth}{\raggedright% \DTLifstringeq{\reference}{}{}{\reference\\}% \DTLifstringeq{\narrative}{}{}{\narrative\\}% } &% \parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})} \DTLiflastrow{% \ifthenelse{\equal{\STM@JK@closingbalance}{none}}% {}% {\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}% {\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}% \\\bottomrule% }% {\\ & & \\}% }% }% \DTLsetseparator{,}% \renewcommand*\STM@JK@noheader{false}% \sisetup{detect-all,round-integer-to-decimal,round-mode=places,round-precision=2}% |
- Zunächst legt man die Reihenfolge der Schlüssel in der
csv
-Datei fest.
1\renewcommand*\STM@JK@dbkeys{ValueDate,PostingDate,Reference,Narrative,Amount,Balance}% - Danach definiert man
\STM@JK@DTLforeach ; ein Makro das die
csv
-Datei zeilenweise einliest und als LaTeX-Tabellenzeile ausgibt. Es nutzt dazu das \DTLforeach Makro (datatool.sty
)
123456789101112131415161718192021\renewcommand*\STM@JK@DTLforeach%{%\DTLforeach{\STM@JK@dbname}%{\postingdate=PostingDate,\valuedate=ValueDate,\reference=Reference,\narrative=Narrative,\amount=Amount,\balance=Balance}%{%\parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &%\parbox[t]{\STM@JK@referencewidth}{\raggedright%\DTLifstringeq{\reference}{}{}{\reference\\}%\DTLifstringeq{\narrative}{}{}{\narrative\\}%} &%\parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})}\DTLiflastrow{%\ifthenelse{\equal{\STM@JK@closingbalance}{none}}%{}%{\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}%{\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}%\\\bottomrule%}%{\\ & & \\}%}%}%- Als erstes Argument übergibt man den Namen der
csv
-Datei. Keine Änderung! - Im zweiten Argument mappt man die
csv
-Schlüssel auf Makros - Im dritten und letzten Argument erfolgt die Ausgabe der dreispaltigen Tabellenzeile
- In der ersten Spalte erfolgt die Ausgabe des Buchungs- und Wertstellungstags
1\parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &% - In der zweiten Spalte wird der Verwendungszweck ausgegeben, der aus mehreren
csv
-Schlüsseln aufgebaut sein kann.
1234\parbox[t]{\STM@JK@referencewidth}{\raggedright%\DTLifstringeq{\reference}{}{}{\reference\\}%\DTLifstringeq{\narrative}{}{}{\narrative\\}%} &% - In der dritten Spalte erfolgt die Ausgabe des Betrags. Ein negativer Betrag wird dabei in Rot (negativcolor Option) gesetzt
1\parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})} - Abschließend erfolgt ein Test auf die letzte Datenzeile und die Ausgabe des Schlußsaldos bzw. einer Leerzeile
1234567\DTLiflastrow{%\ifthenelse{\equal{\STM@JK@closingbalance}{none}}%{}%{\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}{\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}%\\\bottomrule%}%{\\ & & \\}%
- In der ersten Spalte erfolgt die Ausgabe des Buchungs- und Wertstellungstags
- Als erstes Argument übergibt man den Namen der
- Im letzten Schritt definieren wir den Trenner der
csv
-Datei und legen fest, ob sie über eine Kopfzeile verfügt (Achtung: header → noheader=false! (noheader Option (datatool.sty))). Die letzte Zeile kann man überlicherweise einfach kopieren (siunitx
-Setup)!
123\DTLsetseparator{,}%\renewcommand*\STM@JK@noheader{false}%\sisetup{detect-all,round-integer-to-decimal,round-mode=places,round-precision=2}%
Damit gelingt hoffentlich die Anpassung und Unterstützung anderer csv
-Formate! 😉