1

Look at the following example. Goal is to have to columns which all values of AD and AA as varnames and the corresponding values in each columns.... The file has to be filtered because there are much more different key-values pairs (not only AX:aa).

\documentclass[landscape,a4paper, ngerman, 10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents*}{c.csv}
AA:BB
AX:sdsd
AX:sdsd
AX:sdsd
AX:sdsd
AX:sdsd
AD:CC
AY:asas
AY:asas
AY:asas
AY:asas
AY:asas
AY:asas
AA:BB
AX:sdsd
AX:sdsd
AX:sdsd
AX:sdsd
AX:sdsd
AD:CC
AY:asas
AY:asas
AY:asas
AY:asas
AY:asas
AY:asas
\end{filecontents*}
\begin{document}


\DTLnewdb{tbase}
\DTLnewrow{tbase}

\DTLsetseparator{:}
\DTLloaddb[keys={ca,cb}]{dbn}{c.csv} 

\section{A}
\DTLforeach[\DTLiseq{\ca}{AA}\OR\DTLiseq{\ca}{AD}]{dbn}{\ca=ca, \cb=cb}{
\DTLifoddrow{%
    \DTLcurrentindex \ \protect\ca \ \protect\cb%
    \DTLnewdbentry{tbase}{\ca}{\cb}%     
    }%
    {%
    \protect\ca \ \protect\cb\\%
    \DTLnewdbentry{tbase}{\ca}{\cb}%
    \DTLnewrow{tbase}%
    }%
}%
\section{B}
\DTLdisplaydb{tbase}

\end{document}

I am sure its a simple mistake ...;(

4

I am not sure that I understood what you want to do. In your c.csv file is no header so you have to use the option noheader for this database.

\DTLloaddb[keys={ca,cb},noheader]{dbn}{c.csv}

Note that an value added to the database is not expanded by default. So when you print the new database tbase the last defintion of \cb is used. But you can set \dtlexpandnewvalue to expand the new values for the database.

And I would use \DTLnewrow{tbase} directly before a new row really starts.

    \documentclass[landscape,a4paper, ngerman, 10pt]{scrartcl}
    \usepackage[utf8]{inputenc}
    \usepackage[ngerman]{babel}
    \usepackage[T1]{fontenc}
    \usepackage{datatool}
    \usepackage{filecontents}

    \begin{filecontents*}{c.csv}
    AA:BB
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AD:CC
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    AA:BB
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AX:sdsd
    AD:CC
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    AY:asas
    \end{filecontents*}
    \begin{document}
    \DTLnewdb{tbase}
    \DTLsetseparator{:}
    \DTLloaddb[keys={ca,cb},noheader]{dbn}{c.csv} 

    \section{A}
    \DTLforeach[\DTLiseq{\ca}{AA}\OR\DTLiseq{\ca}{AD}]{dbn}{\ca=ca, \cb=cb}{%
    \dtlexpandnewvalue%
    \DTLifoddrow{%
        \DTLcurrentindex \ \ca \ \cb%
        \DTLnewrow{tbase}\DTLnewdbentry{tbase}{\ca}{\cb}%     
        }%
        {%
        \ \ca \ \cb\\%
        \DTLnewdbentry{tbase}{\ca}{\cb}%
        }%
    }%

    \section{B}
    \DTLdisplaydb{tbase}
    \end{document}

enter image description here

  • Perfect solution for me. Thank you vey much. – Peter Ebelsberger Sep 26 '15 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.