Home
csvsimple.
Contents
1. Bayern Baden Wiirttemberg Sachsen Th ringen Hessen 27 It would be nice to sort the bars by length i e to sort the CSV file by the amount column If the CSV Sorter program is properly installed see Subsection 3 8 on page 20 this can be done with the following configuration file for CSV Sorter Configuration file amountsort xml lt xml version 1 0 encoding UTF 8 csv bracket empty true gt lt sortlines gt lt column name amount order descending type double gt lt column name land order ascending type string gt lt sortlines gt lt csv gt Now we just have to add an option sort by amountsort xml 4 This example requires the package tikz 4 Also the CSV Sorter tool has to be installed begin tikzpicture Group A style left color red 10 right color red 20 Group B style left color blue 10 right color blue 20 csvreader head to column names sort by amountsort xml data csv 7 begin scope yshift thecsvrow cm path draw Group group 0 0 45 rectangle node font bfseries amount amount 1000 0 45 node left at 0 0 land end scope end tikzpicture Baden Wiirttemberg Hessen Th ringen Bayern Sachsen 28 Next we create a pie chart by calling csvreader twice In the first step the total sum of amounts is computed and in the
2. csvautobooktabular data_headless csv Bayern 1700 Baden Wiirttemberg 2300 Sachsen 1520 Th ringen 1900 Hessen 2100 p 16 ptu To get the expected result one can redefine csv table head using csvlinetotablerow which holds the first line data for the Ncsvauto commands Ncsvautobooktabular table head toprule csvlinetotablerow data_headless csv Bayern 1700 Baden Wiirttemberg 2300 Sachsen 1520 Thiringen 1900 Hessen 2100 This example can be extended to insert a table head for this headless data csvautobooktabular table head toprule bfseries Land amp bfseries Group amp bfseries Amount midrule csvlinetotablerow data_headless csv Land Amount Bayern 1700 Baden Wiirttemberg 2300 Sachsen 1520 Th ringen 1900 Hessen 2100 34 Pr q P 14 For the normal csvreader command the csv no hea option should be applied Of course we cannot use csv head to column names P 14 because there is no head but the columns can be addressed by their numbers csvreader no head tabular lr table head toprule bfseries Land amp bfseries Amount midrule table foot bottomrule data_headless csv 1 land 3 amount land amp amount Land Amount Bayern 1700 Baden Wiirttemberg 2300 Sachsen 1520 Th ringen 1900 Hessen 2100 35 4 6 Imported CSV data If data is important from other applications there is not always a choice to format in comma separated value
3. 2 A colored ball 3 Another formula lim 1 0 noo TL Now formulas only 1 A nice formula J Inx c 2 Another formula lim t 0 noo TL 31 4 4 Tables with Number Formatting We consider a file with numerical data which should be pretty printed CSV file data numbers csv month dogs cats January 12 50 12 3e5 February 3 32 8 7e3 March 43 3 1e6 April 0 33 21 2e4 May 5 12 3 45e6 June 6 44 6 66e6 July 123 2 7 3e7 August 3e4 September 2 3 4e4 October 6 5 be6 November 0 55 5 5e5 December 2 2 3e3 The siunitx 7 package provides a new column type S which can align material using a number of different strategies The following example demonstrates the application with CSV reading The package documentation 7 contains a huge amount of formatting options 4 Yusepackagetsiunitz array booktabs csvloop file data_numbers csv head to column names before reading centering sisetup table number alignment center tabular 1SS table format 2 2e1 table head toprule textbf Month amp textbf Dogs amp textbf Cats midrule command month amp dogs amp cats table foot bottomrule Month January February March April May June July August September October November December 32 Now the preceding table shall be sorted by the cats values If the CSV Sorter program is prop erly installed see Subsection 3 8 on page 20 this can be done with the f
4. The csvsimple package Manual for version 1 12 2014 07 14 Thomas F Sturm Abstract csvsimple provides a simple IATEX interface for the processing of files with comma separated values CSV csvsimple relies heavily on the key value syntax from pgfkeys which results hopefully in an easy way of usage Filtering and table gen eration is especially supported Since the package is considered as a lightweight tool there is no support for data sorting or data base storage Contents 1 Introduction 2 1 1 Loading the Package i 3 26644282 kk m ES Ree haa we 2 1 2 First Steps es os mouca eee n m ee Rom RR E ee gy 9 Roh CRUS oes 2 2 Macros for the Processing of CSV Files 7 3 Option Keys 13 31 Command Definition e iux dos x Ron o paipa eee eom XU n e 13 3 2 Header Processing and Column Name Assignment 14 3 3 Consistency Check and Filtering llle 15 9 1 Table SuppOPb ss ce 4 a eee eA Ra UR eA ue ORO e om C Ets 16 2 9 special Characters s s ss osos Rog oom Rod e OR Reed ee ee ee 17 29 0 Separators e s Gee ate e Ros E Ao M E rok dew ee ge ee ee B Pe doe s 18 3 Miscellaneous 4 22529 no so Re ee s 19 9 8 Soitin s 2m B EUR Skah OR SR See eee oou wed Mo Re de d 20 4 Examples 25 4 A Serial better g s sd toe oana tA Ron RU RR YS eek ee oR aeta 25 4 2 A Graphical Presentation 2 2 2 2 000 0 ee ee 27 43 Macro code inside the data 2 2 02 llle 3l 4 4 Tables with Number
5. style no default Like csv tabular but inside an additional center environment csv longtable table format style no default Like csv tabular but for the longtable environment This requires the package longtable not loaded automatically csv tabbing style no value Like csv tabular but for the tabbing environment csv centered tabbing style no value Like csv tabbing but inside an additional center environment csv no table style no value Deactivates tabular longtable and tabbing csv before table macros no default initially empty Sets the macros to be executed before begin tabular or before begin longtable or before begin tabbing respectively csv table head macros no default initially empty Sets the macros to be executed after begin tabular or after begin longtable or after begin tabbing respectively csv table foot macros no default initially empty Sets the macros to be executed before end tabular or before end longtable or before end tabbing respectively csv after table macros no default initially empty Sets the macros to be executed after end tabular or after end longtable or after end tabbing respectively The following auto options are the counterparts for the respective quick overview commands like csvautotabular They are listed for completeness but are unlikely to be used directly csv autotabular file name no default Re
6. 20 csvsorter configpath 20 csvsorter log 20 csvsorter token 21 default 19 every csv 19 file 19 filter 15 filter accept all 15 filter equal 15 filter not equal 15 filter reject all 15 head 14 head to column names 14 late after first line 13 late after head 13 late after last line 13 late after line 13 longtable 16 new sorting rule 24 no check column count 15 no filter 15 no head 14 no preprocessing 19 no table 16 on column count error 15 preprocessed file 19 preprocessor 19 respect all 17 and 17 backslash 17 circumflex 17 dollar 17 leftbrace 17 none 17 percent 17 rightbrace 17 sharp 17 tab 17 tilde 17 underscore 17 respect respect respect respect respect respect respect respect respect respect respect respect separator 18 sort by 21 tabbing 16 table foot 16 table head 16 tabular 16 warn on column count error 15 late late after first line key 13 after head key 13 late after last line key 13 late after line key 13 longtable key 16 new sorting rule key 24 no check column count key 15 no filter key 15 head key 14 preprocessing key 19 table key 16 no no no on column count error key 15 pipe value 18 preprocessed file key 19 preprocessor key 19 all key 17 and key 17 backslash key 17 circumflex key 17 dollar key 17 leftbrace key 17 none key 17 percent key 17 rightbrace key 17 sharp key 17 tab k
7. csvset csvsorter log outdir jobname csvtoken Here the token file is written to a subdirectory named outdir csv sort by file name style initially unset The file name denotes an XML configuration file for CSV Sorter Setting this option inside csvreader 7 or csvloop P will issue a system call to CSV Sorter e CSV Sorter uses the given CSV file as input file e CSV Sorter uses file name as configuration file e The output CSV file is denoted by csv preprocessed file which is by default Njobname sorted csv This output file is this actual file processed by csvreader P7 or Ncsvloop P CSV Sorter also generates a log file denoted by csv csvsorter log by default csvsorter 1log gt P 19 P 20 which is First example To sort our example grade csv file according to name and givenname we use the following XML configuration file Since CSV Sorter uses double quotes as default brackets for column values we remove bracket recognition to avoid a clash with the escaped umlauts of the example CSV file Configuration file namesort xml lt xml version 1 0 encoding UTF 8 csv lt bracket empty true lt sortlines gt lt column name name order ascending type string gt lt column name givenname order ascending type string gt lt sortlines gt lt csv gt 4 usepackaget booktabs csvreader sort by namesort xml head to column names tabular gt color red 11111 table he
8. processed This command overwrites all previous filter settings and may be used inside csv before filter to implement an own filtering rule together with csvfilterreject csvreader autotabular before filter ifthenelse equal csvcoliv m csvfilteraccept csvfilterreject i grade csv csvlinetotablerow 7 name givenname matriculation gender grade Maier Hans 12345 m 1 0 Weifb ck Werner 34567 m 5 0 csvfilterreject All following data lines will be ignored This command overwrites all previous filter settings csvline This macro contains the current and unprocessed data line csvreader no head tabbing table head textit line XX kill 7 grade csv textit line thecsvrow gt csvline line 1 name givenname matriculation gender grade line 2 Maier Hans 12345 m 1 0 line 3 Huber Anna 23456 1 2 3 line 4 WeiBback Werner 34567 m 5 0 line 5 Bauer Maria 19202 3 3 thecsvrow Typesets the current data line number This is the current number of accepted data lines without the header line The IATEX counter csvrow can be addressed directly in the usual way e g by roman csvrow thecsvinputline Typesets the current file line number This is the current number of all data lines including the header line The IXTEX counter csvinputline can be addressed directly in the usual way e g by roman csvinputline csvreader no head filter equal thecsvinputlin
9. set after after line csv after reading macros no default initially empty Sets the macros to be executed after the CSV file is processed 13 csvreader before reading meta before reading after head meta after head before filter metatbefore filter late after head metaf late after head late after line metat late after line late after first line metaf late after first line late after last line metaf late after last line before line meta before line before first line meta before first line after line metafafter line after first line meta after first line after reading meta after reading grade csv name name textbf name before reading after head before filter late after head before first line Maier after first line before filter late after first line before line Huber after line before filter late after line before line WeiBback after line before filter late after line before line Bauer after line late after last line after reading Additional command definition keys are provided for the supported tables see section 3 4 from page 16 3 2 Header Processing and Column Name Assignment csv head true false default true initially true If this key is set the first line of the CSV file is treated as a header line which can be used for column name assignments csv no head no value Abbreviation for head
10. 16 autobooktabular key 16 autolongtable key 16 autotabular key 16 before filter key 13 before first line key 13 before line key 13 before reading key 13 before table key 16 centered tabbing key 16 centered tabular key 16 check column count key 15 column count key 15 column names key 14 column names reset key 14 comma value 18 command key 13 csvautobooklongtable 9 csvautobooktabular 9 csvautolongtable 8 csvautotabular 8 csvcoli 7 csvcolii 7 csvcoliii 7 csvfilteraccept 12 csvfilterreject 12 csvheadset 10 csviffirstrow 11 csvifoddrow 11 csvline 12 csvlinetotablerow 12 csvloop 7 csvnames 10 csvreader 7 csvset 10 csvsorter command key 20 csvsorter configpath key 20 csvsorter log key 20 csvsorter token key 21 csvstyle 10 default key 19 every csv key 19 file key 19 filter key 15 filter accept all key 15 filter equal key 15 filter not equal key 15 38 filter reject all key 15 head key 14 head to column names key 14 Keys csv after first line 13 after head 13 after line 13 after reading 13 after table 16 autobooklongtable 16 autobooktabular 16 autolongtable 16 autotabular 16 before filter 13 before first line 13 before line 13 before reading 13 before table 16 centered tabbing 16 centered tabular 16 check column count 15 column count 15 column names 14 column names reset 14 command 13 csvsorter command
11. Elfred Esplanade T g 37 CEresung 60 Now we create the serial letter where every feasible data line produces an own page Here we simulate the page by a tcolorbox from the package tcolorbox For the gender specific salutations an auxiliary macro ifmale is introduced 25 4 this example requires the tcolorbog package newcommand ifmale 2 ifthenelse equal gender m 1 2 csvreader head to column names address csv begin tcolorbox colframe DarkGray colback White arc 0mm width linewidth 2pt 2 equal height group letter before after hfill fonttitle bfseries adjusted title Letter to name ifthenelse equal degree ifmale Mr Ms degree givenname name street zip location tcblower itshape Dear ifmale Sir Madam we are pleased to announce you a bonus value of bonus which will be delivered to location soon ldots end tcolorbox Letter to Maier Mr Hans Maier Am Bachweg 17 10010 Hopfingen we are pleased to announce you a bonus value of 20 which will be delivered to Hopfingen soon Letter to Weifback Prof Dr Werner Weiflb ck Brauallee 10 10030 Klingenbach Dear Sir we are pleased to announce you a bonus value of 4096 which will be delivered to Klingen bach soon Letter to Schmitt Mr Anton Schmitt ZElfred Esplanade Tzeg 37 10050 CEresung we are pleased to announce you a bonus value of 60 whi
12. Formatting 4l lee 32 4 5 CSV data without headerline 2 22 34 4 6 Imported CSV data s si 4 ke a be Sts eee cR RE SR oe a Ai RR eee d RR da 36 References 37 Index 38 Prof Dr Dr Thomas F Sturm Institut f r Mathematik und Informatik Universitat der Bundeswehr M nchen D 85577 Neubiberg Germany email thomas sturm unibw de 1 Introduction The csvsimple package is applied to the processing of CSV files This processing is controlled by key value assignments according to the syntax of pgfkeys 6 Sample applications of the package are tabular lists serial letters and charts An alternative to csvsimple is the datatool package 5 which provides considerably more functions and allows sorting of data by LXTEgX csvsimple has a different approach for the user interface and is deliberately restricted to some basic functions with fast processing speed Sorting is not supported directly but can be done with external tools see Section 3 8 on page 20 1 1 Loading the Package The package csvsimple loads the packages pgfkeys 6 and ifthen l csvsimple itself is loaded in the usual manner in the preamble usepackage csvsimple Not automatically loaded but used for many examples are the packages longtable 2 and booktabs 3 1 2 First Steps Every line of a processable CSV file has to contain an identical amount of comma separated values The curly braces of TEX groups can be used to mask a bl
13. ad toprule Name amp Given Name amp Matriculation amp Gender amp Grade midrule table foot bottomrule grade csv csvlinetotablerow Name Given Name Matriculation Gender Bauer Maria 19202 f Huber Anna 23456 f Maier Hans 12345 m WeifBba ck Werner 34567 m 21 Second example To sort our example grade csv file according to grade we use the following XML configuration file Further persons with the same grade are sorted by name and givenname Since CSV Sorter uses double quotes as default brackets for column values we remove bracket recognition to avoid a clash with the escaped umlauts of the example CSV file Configuration file gradesort xml lt xml version 1 0 encoding UTF 8 csv lt bracket empty true lt sortlines gt lt column name grade order ascending type double gt lt column name name order ascending type string gt lt column name givenname order ascending type string gt lt sortlines gt lt csv gt 4 usepackaget booktabs csvreader sort by gradesort xml head to column names tabular 1111 gt color red 1 table head toprule Name amp Given Name amp Matriculation amp Gender amp Grade midrule table foot bottomrule grade csv csvlinetotablerow Name Given Name Matriculation Gender Grade Maier Hans 12345 m 1 0 Huber Anna 23456 f 2 9 Bauer Maria 19202 f d Weifba ck Werner 34567 m 5 0 22 Third example To generate a mat
14. ads the whole CSV file denoted file name with an automated formatting csv autolongtable file name no default Reads the whole CSV file denoted file name with an automated formatting using the required longtable package csv autobooktabular file name no default Reads the whole CSV file denoted file name with an automated formatting using the required booktabs package csv autobooklongtable file name no default Reads the whole CSV file denoted file name with an automated formatting using the required booktabs and longtable packages 16 3 5 Special Characters Be default the CSV content is treated like normal IATEX text see Subsection 4 3 on page 31 But TEX special characters of the CSV content may also be interpreted as normal characters if one or more of the following options are used csv respect tab true false default true initially false If this key is set every tabulator sign inside the CSV content is a normal character csv respect percent true false default true initially false If this key is set every percent sign 4 inside the CSV content is a normal character csv respect sharp true false default true initially false If this key is set every sharp sign inside the CSV content is a normal character csv respect dollar true false default true initially false If this key is set every dollar sign inside the CSV content is a normal character csv respect and true false def
15. ault true initially false If this key is set every and sign inside the CSV content is a normal character csv respect backslash true false default true initially false If this key is set every backslash sign inside the CSV content is a normal character csv respect underscore true false default true initially false If this key is set every underscore sign inside the CSV content is a normal character csv respect tilde true false default true initially false If this key is set every tilde sign inside the CSV content is a normal character csv respect circumflex true false default true initially false If this key is set every circumflex sign inside the CSV content is a normal character csv respect leftbrace true false default true initially false If this key is set every left brace sign 1 inside the CSV content is a normal character csv respect rightbrace true false default true initially false If this key is set every right brace sign inside the CSV content is a normal character csv respect all style no value initially unset Set all special characters from above to normal characters This means a quite verbatim interpretation of the CSV content csv respect none style no value initially set Do not change any special character from above to normal character 17 3 6 Separators csv separator sign no default initially comma Sets the sign which is treates as separa
16. ble foot hline grade csv csvifoddrow slshape thecsvrow amp slshape name givenname amp slshape grade bfseries thecsvrow amp bfseries name givenname amp bfseries grade Name Grade Maier Hans 1 0 Huber Anna 2 3 Weifb ck Werner 5 0 Bauer Maria 3 3 The csvifoddrow macro may be used for striped tables 4 This example needs the zcolor package csvreader head to column names tabular rlcc table head hline rowcolor red 50 black color white amp color white Person amp color white Matr No amp color white Grade late after head hline rowcolor yellow 50 late after line csvifoddrow rowcolorfyellow 50 rowcolor red 25 7 grade csv 7 Z thecsvrow amp givenname name amp matriculation amp Ngrade Z Person Matr No Grade Hans Maier il 1 0 Anna Huber Maria Bauer 19202 Alternatively Nrowcolors from the xcolor package can be used for this purpose 4 This example needs the zcolor package Ncsvreader tabular rlcc before table rowcolors 2 red 25 yellow 50 table head hline rowcolor red 50 black color white amp color white Person amp color white Matr No amp color white Grade hline head to column names grade csv 7 thecsvrow amp givenname name amp matriculation amp grade Person Matr No Grade Anna Huber Maria Bauer 11 csvfilteraccept All following consistent data lines will be accepted and
17. ch will be delivered to resung soon 26 Letter to Huber Dr Erna Huber Moosstrafe 32 Hinterschlag 10020 Ortingstetten Dear Madam we are pleased to announce you a bonus value of 3096 which will be delivered to Ortingstet ten soon Letter to Siebener Mr Franz Siebener Blaumeisenweg 12 10040 Pardauz we are pleased to announce you a bonus value of 5096 which will be delivered to Pardauz soon 4 2 A Graphical Presentation For this example we use some artificial statistical data given by a CSV file CSV file data csv land group amount Bayern A 1700 Baden W u rttemberg A 2300 Sachsen B 1520 Th u ringen A 1900 Hessen B 2100 Firstly we survey the file content using csvautobooktabular 4 needs the booktabs package csvautobooktabular data csv land amount Bayern 1700 Baden Wiirttemberg 2300 Sachsen 1520 Th ringen 1900 Hessen 2100 The amount values are presented in the following diagram by bars where the group classification is given using different colors 4 This example requires the package tikz begin tikzpicture Group A style left color red 10 right color red 20 Group B style left color blue 10 right color blue 20 csvreader head to column names data csv begin scope yshift thecsvrow cm path draw Group group 0 0 45 rectangle node font bfseries amount amount 1000 0 45 node left at 0 0 land end scope end tikzpicture
18. ck Maria Bauer 19202 Maria Bauer The data lines of a CSV file can also be filtered In the following example a certificate is printed only for students with grade unequal to 5 0 csvreader filter not equal grade 5 0 7 grade csv 1 name 2 firstname 3 matnumber 4 gender 5 grade 7 begin center Large bfseries Certificate in Mathematics end center large ifthenelse equal gender f Ms Mr firstname name matriculation number matnumber has passed the test in mathematics with grade grade par ldots par I4 Certificate in Mathematics Mr Hans Maier matriculation number 12345 has passed the test in mathematics with grade 1 0 Certificate in Mathematics Ms Anna Huber matriculation number 23456 has passed the test in mathematics with grade 2 3 Certificate in Mathematics Ms Maria Bauer matriculation number 19202 has passed the test in mathematics with grade 3 3 2 Macros for the Processing of CSV Files csvreader options file name assignments command list csvreader reads the file denoted by file name line by line Every line of the file has to contain an identical amount of comma separated values The curly braces of TEX groups can be used to mask a block which may contain commas not to be processed as separators The first line of such a CSV file is by default but not necessarily processed as a header line which co
19. design The following example is easily modified to obtain more or less option settings csvset myStudentList style tabular r 1llcl table head hline amp Person amp 1 hline hline late after line hline column names name Nname givenname Mfirstname csvreader myStudentList Matr No grade csv matriculation matnumber thecsvrow amp firstname name amp matnumber hfillZ csvreader myStudentList Grade grade csv grade grade thecsvrow amp firstname name amp grade 7 Person Matr No Person Hans Maier 12345 Hans Maier Anna Huber 23456 Anna Huber Werner Weifback 34567 Werner Weifback Maria Bauer 19202 Maria Bauer Alternatively column names can be set by csvnames 19 csvstyle 9 With this the last example is rewritten as follows and style definitions by csvnames myNames 1 name 2 firstname 3 matnumber 5 grade csvstyle myStudentList tabular rl1lcl table head hline amp Person amp 1 hline hline late after line hline myNames csvreader myStudentList Matr No grade csv 7 thecsvrow amp firstname name amp matnumber hfill7 csvreader myStudentList Grade grade csv thecsvrow amp firstname name amp grade 7 Person Matr No Person Hans Maier 12345 Hans Maier Anna Huber 23456 Anna Huber Werner Weifback 34567 Werner Weifba
20. e 3 7 grade csv The line with number thecsvinputline contains csvline The line with number 3 contains Huber Anna 23456 f 2 3 csvlinetotablerow Typesets the current processed data line with amp between the entries 12 3 Option Keys For the options in Ncsvreader P7 respectively csvloop 7 the following pgf keys can be applied The key tree path csv is not to be used inside these macros 3 1 Command Definition csv before reading macros no default initially empty Sets the macros to be executed before the CSV file is processed csv after head macros no default initially empty Sets the macros to be executed after the header line is read csv before filter macros no default initially empty Sets the macros to be executed after reading and consistency checking of a data line They are executed before any filter condition is checked see csv filter 5 csv late after head macros no default initially empty Sets the macros to be executed after reading and disassembling of the first accepted data line They are executed before further processing of this line csv late after line macros no default initially empty Sets the macros to be executed after reading and disassembling of the next accepted data line after csv before filter They are executed before further processing of this next line late after line overwrites late after first line and late after last line Not
21. e amp csvcoliii Hans Maier 12345 Anna Huber 23456 Werner Weif b ck 34567 Maria Bauer 19202 Mainly the csvreader command consists of a csvloop macro with following parameters csvloop options file file name column names assignments command command list Therefore the application of the keys csv file for csvreader Pi 19 d P13 and csv comman is useless csvloop options Usually csvreader may be preferred instead of csvloop csvreader is based on csvloop which takes a mandatory list of options in key value syntax This list of options controls the total processing Especially it has to contain the CSV file name csvloop file grade csv head to column names command name before reading List of students late after line late after last line List of students Maier Huber Weifback Bauer The following csvauto commands are intended for quick data overview with limited for matting potential See Subsection 3 4 on page 16 for the general table options in combination with csvreader P and Ncsvloop P7 csvautotabular options file name csvautotabular is an abbreviation for the application of the option key csv autotabular together with other options to Ncsvloop 7 This macro reads the whole CSV file denoted by file name with an automated formatting csvautotabular grade csv name givenname matriculation Maie
22. e preamble csvset new sorting rule name namesort xml Now we can use the new rule csvautotabular sort by name grade csv name givenname matriculation Bauer Maria 19202 Huber Anna 23456 Maier Hans 12345 Weifback Werner 34567 24 4 Examples 4 1 A Serial Letter In this example a serial letter is to be written to all persons with addresses from the following CSV file Deliberately the file content is not given in very pretty format CSV file address csv name givenname gender degree street zip location bonus Maier Hans m Am Bachweg 17 10010 Hopfingen 20 4 next line with a comma in curly braces Huber Erna f Dr Moosstra ss e 32 Hinterschlag 10020 O rtingstetten 30 Wei ss b a ck Werner m Prof Dr Brauallee 10 10030 Klingenbach 40 4 this line is ignored Z4 Siebener Franz m Blaumeisenweg 12 10040 Pardauz 50 4 preceding and trailing spaces in entries are removed Schmitt Anton m AE lfred Esplanade T ae g 37 10050 0E resung 60 Firstly we survey the file content quickly using csvautotabular As can be seen unfeasible lines are ignored automatically tiny csvautotabular address csv name givenname degree street location bonus Maier Hans Am Bachweg 17 Hopfingen 20 Huber Erna Dr Moosstrafe 32 Hinterschlag Ortingstetten 30 Weifb ck Werner Prof Dr Brauallee 10 Klingenbach 40 Siebener Franz Blaumeisenweg 12 Pardauz 50 Schmitt Anton J
23. e that table options like csv tabular set this key to automatically csv late after first line macros no default initially empty Sets the macros to be executed after reading and disassembling of the second accepted data line instead of csv 1ate after line This key has to be set after late after line csv late after last line macros no default initially empty Sets the macros to be executed after processing of the last accepted data line instead of csv late after line This key has to be set after late after line csv before line macros no default initially empty Sets the macros to be executed after csv late after line and before csv command before line overwrites before first line csv before first line macros no default initially empty Sets the macros to be executed instead of csv before line for the first accepted data line This key has to be set after before line csv comnand macros no default initially csvline Sets the macros to be executed for every accepted data line They are executed between csv before line and csv after line csv after line macros no default initially empty Sets the macros to be executed for every accepted data line after csv command after line overwrites after first line csv after first line macros no default initially empty Sets the macros to be executed instead of csv after line for the first accepted data line This key has to be
24. eprocessing i e preprocessing is switched of default is used because of the global nature of most settings 19 3 8 Sorting TEX IATEX was not born under a sorting planet csvsimple provides no sorting of data lines by IXTEX methods since sorting can be done much faster and much better by external tools First one should consider the appropriate place for sorting e CSV files may be sorted by a tool before the IXTEX document is processed at all If the CSV data is not likely to change this is the most efficient method e CSV files may be sorted by a tool every time before the ATEX document is compiled This could be automated by a shell script or some processing tool like arara e CSV files may be sorted on the fly by a tool during compilation of a IATEX document This is the most elegant but not the most efficient way The first two methods are decoupled from anything concerning csvsimple For the third method the csv preprocessor option is made for This allows to access an external tool for sorting Which tool is your choice CSV Sorter 4 was written as a companion tool for csvsimple It is an open source Java command line tool for sorting CSV files available at http T F S github io csvsorter or https github com T F S csvsorter It can be used for all three sorting approaches described above There is special support for on the fly sorting with CSV Sorter using the following options 1 To use the sorting o
25. erlin hans meier corporation de The file which is generated on the fly and which is actually read by csvsimple is the following name address email Frank Smith Yellow Road 123 Brimblsby frank smith organization org Mary May Blue Alley 2a London mmay maybe uk Hans Meier Hauptstrasse 32 Berlin hans meier corporation de 36 References 1 David Carlisle The ifthen package May 26 2001 http mirror ctan org macros latex base 2 David Carlisle The longtable package Feb 1 2004 http mirror ctan org macros latex required tools longtable pdf 3 Simon Fear Publication quality tables in ATX Apr 15 2005 http mirror ctan org macros latex contrib booktabs booktabs pdf 4 Thomas F Sturm The CSV Sorter program Manual for version 0 94 beta July 14 2014 http T F S github io csvsorter csvsorter pdf 5 Nicola L C Talbot User Manual for the datatool bundle version 2 20 Feb 3 2014 http mirror ctan org macros latex contrib datatool datatool pdf 6 Till Tantau The TikZ and PGF Packages Manual for version 3 0 0 Dec 20 2013 http sourceforge net projects pgf 7 Joseph Wright si unitz A comprehensive SI units package July 31 2013 http mirror ctan org macros latex contrib siunitx siunitx pdf 37 Index after first line key 13 after head key 13 after line key 13 after reading key 13 after table key 16 autobooklongtable key
26. ey 17 tilde key 17 underscore key 17 respect respect respect respect respect respect respect respect respect respect respect respect respect semicolon value 18 separator key 18 sort by key 21 tab value 18 tabbing key 16 table foot key 16 table head key 16 39 tabular key 16 thecsvinputline 12 thecsvrow 7 12 Values comma 18 pipe 18 semicolon 18 tab 18 warn on column count error key 15
27. false i e the first line of the CSV file is treated as data line Note that this option cannot be used in combination with csvautotabular 5 csv autotabular and similar automated commands options See Section 4 5 on page 34 for assistance csv column names assignments no default initially empty Adds some new assignments of macros to columns in key value syntax Existing assign ments are kept csv column names reset no value Clears all assignments of macros to columns csv head to column names true false default true initially false If this key is set the entries of the header line are used automatically as macro names for the columns This option can be used only if the header entries do not contain spaces and special characters to be used as feasible IATEX macro names 14 3 3 Consistency Check and Filtering csv check column count true false default true initially true This key defines if the number of entries in a data line is checked against an expected value If true every non consistent line is ignored without announcement If false every line is accepted and may produce an error during further processing csv no check column count no value Abbreviation for check column count false csv column count number no default Sets the number of feasible entries per data line This setting is only useful in connection with csv no head since number would be replaced by the number of ent
28. ly inserted by csv late after line This defines a macro execution just before the following line Additionally the assignment of columns to TEX macros is shown in a non automated way begin tabular r 1 c hlineZ amp Person amp Matr No hline hline csvreader late after line hline grade csv name name givenname firstname matriculation matnumber thecsvrow amp firstname name amp matnumber end tabular Person Hans Maier Anna Huber Werner Weifback Maria Bauer An even more comfortable and preferrable way to create a table is setting appropriate option keys Note that this gives you the possibility to create a pgfkeys style which contains the whole table creation csvreader tabular rl1lcl table head hline amp Person amp Matr No hline hline late after line hline grade csv name name givenname firstname matriculation matnumber thecsvrow amp firstname name amp matnumber 7Z Person Matr No Hans Maier 12345 Anna Huber 23456 Werner Weifback 34567 Maria Bauer 19202 The next example shows such a style definition with the convenience macro csvstyle P 0 Here we see again the automated assignment of header entries to column names by csv head to column names For this the header entries have to be without spaces and special characters But you can always assign entries to cano
29. nical macro names by hand like in the examples above Ncsvstyle myTableStyle tabular rlllcl table head hline amp Person amp Matr No hline hline late after line hline head to column names csvreader myTableStyle grade csv thecsvrow amp givenname name amp matriculation Person Matr No Hans Maier 12345 Anna Huber 23456 Werner Weifback 34567 Maria Bauer 19202 Another way to address columns is to use their roman numbers The direct addressing is done by csvcoli csvcolii csvcoliii Ncsvreader tabular rlllcl table head hline amp Person amp Matr No hline hline late after line hline grade csv thecsvrow amp Ncsvcolii Ncsvcoli amp Ncsvcoliii Z Person Matr No Hans Maier 12345 Anna Huber 23456 Werner Weifback 34567 Maria Bauer 19202 And yet another method to assign macros to columns is to use arabic numbers for the assignment Ncsvreader tabular rl llcl table head hline amp Person amp Matr No hline hline late after line hline grade csv 1 name 2 firstname 3 matnumber thecsvrow amp firstname name amp matnumber Person Matr No Hans Maier 12345 Anna Huber 23456 Werner Weifback 34567 Maria Bauer 19202 For recurring applications the pgfkeys syntax allows to create own styles for a consistent and centralized
30. ntains the identifiers for each column The entries of this line can be used to give assignments to TEX macros to address the columns The number of entries of this first line determines the accepted number of entries for all following lines Every line which contains a higher or lower number of entries is ignored during standard processing The assignments are given by key value pairs name macro Here name is an entry from the header line or the arabic number of the addressed column macro is some TEX macro which gets the content of the addressed column The command list is executed for every accepted data line Inside the command list is applicable e thecsvrow or the counter csvrow which contains the number of the current data line starting with 1 e csvcoli csvcolii csvcoliii which contain the contents of the column entries of the current data line Alternatively can be used e macro from the assignments to have a logical addressing of a column entry Note that the command list is allowed to contain par and that all macro definitions are made global to be used for table applications The processing of the given CSV file can be controlled by various options given as key value list The feasible option keys are described in section 3 from page 13 Ncsvreader tabular r l l table head hline table foot hline grade csv 7 name name givenname firstname grade grade 7 grade amp firstname nam
31. ock which may contain commas not to be processed as separators The first line of such a CSV file is usually but not necessarily a header line which contains the identifiers for each column CSV file grade csv name givenname matriculation gender grade Maier Hans 12345 m 1 0 Huber Anna 23456 f 2 3 Wei ss b a ck Werner 34567 m 5 0 Bauer Maria 19202 f 3 3 The most simple way to display a CSV file in tabular form is the processing with the csvautotabular P 5 command csvautotabular grade csv name givenname matriculation Maier Hans 12345 Huber Anna 23456 Weifback Werner 34567 Bauer Maria 19202 2CSV file file with comma separated values 3See csv separator for other separators than comma APT Typically one would use csvreader instead of csvautotabular to gain full control over the interpretation of the included data In the following example the entries of the header line are automatically assigned to TEX macros which may be used deliberately begin tabular 1 c hlineZ bfseries Person amp bfseries Matr No csvreader head to column names grade csv givenname name amp matriculation hline end tabular Person Matr No Hans Maier 12345 Anna Huber 23456 Werner Weifback 34567 Maria Bauer 19202 csvreader is controlled by a plenty of options For example for table applications line breaks are easi
32. ollowing configuration file for CSV Sorter Configuration file catsort xml lt xml version 1 0 encoding UTF 8 csv lt bracket empty true gt lt sortlines gt lt column name cats order ascending type double gt lt sortlines gt lt csv gt Now we just have to add an option sort by catsort xml 4 Yusepackagetsiunitz array booktabs 4 Also the CSV Sorter tool has to be installed csvloop file data_numbers csv sort by catsort xml head to column names before reading centering sisetup table number alignment center tabular 1SS table format 2 2e1 table head toprule textbf Month amp textbf Dogs amp textbf Cats midrule command month amp dogs amp cats table foot bottomrule Month December February September August April November January March May October June July 33 4 5 CSV data without header line CSV files with a header line are more semantic than files without header but it s no problem to work with headless files For this example we use again some artificial statistical data given by a CSV file but this time without header CSV file data_headless csv Bayern A 1700 Baden W u rttemberg A 2300 Sachsen B 1520 Th u ringen A 1900 Hessen B 2100 Note that you cannot use the csv no head option for the auto tabular commands If no options are given the first line is interpreted as header line which gives an unpleasant result
33. or the application of the option key csv autobooklongtable 6 together with other options to Ncsvloop P This macro reads the whole CSV file denoted by file name with an automated formatting For application the packages booktabs and longtable are required which have to be loaded in the preamble Ncsvautobooklongtable grade csv name givenname matriculation gender grade Maier Hans 12345 m 1 0 Huber Anna 23456 f 2 3 Weifb ck Werner 34567 m 5 0 Bauer Maria 19202 f 3 3 csvset options Sets options for every following csvreader command may be used for style definitions P 7 and Ncsvloop P For example this csvset grade list style column names name name givenname firstname grade grade passed style filter not equal grade 5 0 The following students passed the test in mathematics csvreader grade list passed grade csv firstname name grade The following students passed the test in mathematics Hans Maier 1 0 Anna Huber 2 3 Maria Bauer 3 3 csvstyle Stilname options Abbreviation for csvset style name style options to define a new style csvnames Stilname Zuweisungsliste Abbreviation for csvset style name style column names assignments to de fine additional assignments of macros to columns csvnames grade list name name givenname firstname grade grade csvstyle passed filter not equal grade 5 0 The following studen
34. oup 1 csvreader head to column names filter equal group 1 data csv 7 let mya myb pgfmathsetmacro nyb myb amount path draw top color 2 25 bottom color 2 50 0 mya 1000 rectangle node land amount 5 myb 1000 F begin tikzpicture fill gray 75 1 0 rectangle 13 0 1 drawGroup A red begin scope xshift 7cm drawGroup B blue end scope end tikzpicture 30 4 3 Macro code inside the data If needed the data file may contain macro code Note that the first character of a data line is not allowed to be the backslash CSV file macrodata csv type description content M A nice textbf formula displaystyle int frac 1 x ln x c G A textcolor red colored ball tikz shadedraw shading ball 0 0 circle 5cm M textbf Another formula displaystyle lim limits_ n to infty frac 1 n 0 Firstly we survey the file content using csvautobooktabular csvautobooktabular macrodata csv type description content A nice formula I Inx ec A colored ball Q Another formula csvstyle my enumerate head to column names before reading begin enumerate after reading end enumerate Ncsvreader my enumerate macrodata csv item description par content bigskip Now formulas only csvreader my enumerate filter equal type M macrodata csv item description qquad content 1 A nice formula f Inx c
35. ptions you have to install CSV Sorter 4 before csvsimple v1 12 or newer needs CSV Sorter v0 94 of newer 2 You have to give permission to call external tools during compilation i e the command line options for latex have to include shell escape csv csvsorter command system command no default initially csvsorter The system command specifies the system call for CSV Sorter without the options If CSV Sorter was completely installed following its documentation there is nothing to change here If the csvsorter jar file is inside the same directory as the IATEX source file you may configure csvset csvsorter command java jar csvsorter jar csv csvsorter configpath path no default initially Sorting with CSV Sorter is done using XML configuration files If these files are not stored inside the same directory as the IATEX source file a path to access them can be configured csvset csvsorter configpath xmlfiles Here the configuration files would be stored in a subdirectory named xmlfiles csv csvsorter log file name no default initially csvsorter log Sets the log file of CSV Sorter to the given file name csvset csvsorter log outdir csvsorter log Here the log file is written to a subdirectory named outdir csv csvsorter token file name no default initially jobname csvtoken Sets file name as token file This is an auxiliary file which communicates the success of CSV Sorter to csvsimple
36. r Hans 12345 Huber Anna 23456 Weifback Werner 34567 Bauer Maria 19202 Ncsvautotabular filter equal csvcoliv f grade csv givenname matriculation gender grade Anna 23456 2 3 Maria 19202 f 3 3 csvautolongtable options file name csvautolongtable is an abbreviation for the application of the option key csv autolongtable 6 together with other options to Ncsvloop 7 This macro reads the whole CSV file denoted by file name with an automated formatting For application the package longtable is required which has to be loaded in the preamble csvautolongtable grade csv name givenname matriculation gender grade Maier Hans 12345 m 1 0 Huber Anna 23456 f 2 3 Weifb ck Werner 34567 m 5 0 Bauer Maria 19202 f 3 3 csvautobooktabular options file name csvautotabular is an abbreviation for the application of the option key csv autobooktabular P 6 together with other options to Ncsvloop P7 This macro reads the whole CSV file denoted by file name with an automated formatting For application the package booktabs is required which has to be loaded in the preamble csvautobooktabular grade csv name givenname matriculation gender Maier Hans 12345 m Huber Anna 23456 f WeiBback Werner 34567 m Bauer Maria 19202 f csvautobooklongtable options file name csvautobooklongtable is an abbreviation f
37. riculation grade list we sort our example grade csv file using the following XML configuration file Again since CSV Sorter uses double quotes as default brackets for column values we remove bracket recognition to avoid a clash with the escaped umlauts of the example CSV file Configuration file matriculationsort xml lt xml version 1 0 encoding UTF 8 lt csv gt lt bracket empty true gt lt sortlines gt lt column name matriculation order ascending type integer gt lt sortlines gt lt csv gt usepackagetbooktabs csvreader sort by matriculationsort xml head to column names tabular gt color red 1l table head toprule Matriculation amp Grade midrule table foot bottomrule grade csv matriculation amp grade Matriculation Grade 12345 1 0 19202 3 3 23456 2 3 34567 5 0 23 csv new sorting rule name file name style initially unset This is a convenience option to generate a new shortcut for often used csv sort by P applications It also adds a more semantic touch The new shortcut option is sort by name which expands to sort by file name Consider the following example csvautotabular sort by namesort xml grade csv name givenname matriculation grade Bauer Maria 19202 3 3 Huber Anna 23456 2 3 Maier Hans 12345 1 0 Weifback Werner 34567 5 0 A good place for setting up a new sorting rule would be inside th
38. ries in the header line otherwise csv on column count error macros no default initially empty macros to be executed for unfeasible data lines csv warn on column count error style no value Display of a warning for unfeasible data lines csv filter conditiom no default Only data lines which fulfill a logical condition are accepted For the condition every term from the ifthen package 1 is feasible To preprocess the data line before testing the condition the option key csv before filter P can be used csv no filter no value initially set Clears a set filter csv filter accept all no value initially set Alias for no filter All consistent data lines are accepted csv filter reject all no value All data line are ignored csv filter equal string A string B style no default Only lines where string A and string B are equal after expansion are accepted csv filter not equal string A string B style no default Only lines where string A and string B are not equal after expansion are accepted 15 3 4 Table Support csv tabular table format style no default Surrounds the CSV processing with begin tabular table format at begin and with end tabular at end Additionally the commands defined by the key values of csv before table csv table head csv table foot and csv after table are ex ecuted at the appropriate places csv centered tabular table format
39. s with curly brackets Consider the following example data file CSV file imported csv name address email Frank Smith Yellow Road 123 Brimblsby frank smith organization org Mary May Blue Alley 2a London mmay maybe uk Hans Meier Hauptstrasse 32 Berlin hans meier corporation de If the CSV Sorter program is properly installed see Subsection 3 8 on page 20 this can be transformed on the fly with the following configuration file for CSV Sorter Configuration file transform xml lt xml version 1 0 encoding UTF 8 csv bracket leftsymbol doublequote rightsymbol doublequote gt lt delimiter signsymbol semicolon lt outBracket leftsymbol braceleft rightsymbol braceright gt lt outDelimiter signsymbol comma gt lt csv gt Now we just have to add an option sort by transform xml to transform the input data Here we actually do not sort 4 Yusepackagetbooktabs arrayJ 4 Also the CSV Sorter tool has to be installed newcommand Header 1 normalfont bfseries 1 csvreader sort by transform xml tabular gt itshape 11 gt ttfamily 1 table head toprule Header Name amp Header Address amp Header email midrule table foot bottomrule imported csv csvlinetotablerow Name Address email Frank Smith Yellow Road 123 Brimblsby frank smith organization org Mary May Blue Alley 2a London mmay maybe uk Hans Meier Hauptstrasse 32 B
40. second step the slices are drawn 4 Modified example from www texample net for pie charts 4 This example needs the packages tikz xzcolor calc definecolorseries myseries rgb step rgb 95 85 55 17 47 37 resetcolorseries myseries 4 a pie slice newcommand slice 4 pgfmathsetmacro midangle 0 5 1 0 5 2 begin scope clip 0 0 1 1 arc 1 2 1 cycle colorlet SliceColor myseries fill inner color SliceColor 30 outer color SliceColor 60 0 0 circle 1cm end scope draw thick 0 0 1 1 arc 1 2 1 cycle node label midangle 4 at midangle 1 pgfmathsetmacro temp min 2 1 10 110 0 3 0 pgfmathsetmacro innerpos max temp 0 5 0 8 node at midangle innerpos 3 y 4 sum of amounts csvreader before reading def mysum 0 data csv amount amount 7 pgfmathsetmacro mysum mysum amount y 4 drawing of the pie chart begin tikzpicture scale 3 def mya 0 def myb 0 csvreader head to column names data csv let mya myb pgfmathsetmacro myb myb amount slice mya mysum 360 myb mysum 360 amount land end tikzpicture 7 Baden Wirttemberg Sachsen Hessen Th ringen 29 Finally the filter option is demonstrated by separating the groups A and B Every item is piled upon the appropriate stack newcommand drawGroup 2 7 def mya 0 def myb 0 node below 3mm at 2 5 0 bfseries Gr
41. tor between the data values of a data line Feasible values are e comma This is the initial value with as separator e semicolon Sets the separator to 4 usepackaget tcolorbox for tcbverbatimurite begin tcbverbatimwrite testsemi csv name givenname matriculation gender grade Maier Hans 12345 m 1 0 Huber Anna 23456 f 2 3 Wei ss b a ck Werner 34567 m 5 0 end tcbverbatimwrite csvaut obooktabular separator semicolon testsemi csv name givenname matriculation gender grade Maier Hans 12345 1 0 Huber Anna 23456 2 3 WeiBback Werner 34567 5 0 e pipe Sets the separator to 4 usepackagef tcolorbox for tcbverbatimurite begin tcbverbatimwrite pipe csv name givenname matriculation gender grade Maier Hans 12345 m 1 0 Huber Anna 23456 2 3 Wei ss b a ck Werner 34567 m 5 0 end tcbverbatimwrite csvaut obooktabular separator pipe pipe csv name givenname matriculation gender Maier Hans 12345 Huber Anna 23456 WeiBback Werner 34567 e tab Sets the separator to the tabulator sign Automatically csv respect tab 1 is set also 18 3 7 Miscellaneous csv every csv style initially empty A style definition which is used for every following CSV file This definition can be over written with user code 4 Sets a warning message for unfeasible data lines Ncsvset every csv style warn on column count error 4 Alternatively Ncsvstylefe
42. ts passed the test in mathematics csvreader grade list passed grade csv firstname name grade The following students passed the test in mathematics Hans Maier 1 0 Anna Huber 2 3 Maria Bauer 3 3 csvheadset assignments For some special cases this command can be used to change the assignments of macros to columns during execution of csvreader 7 and csvloop P csvreader grade csv 7 csvheadset name n fbox n csvheadset givenname n ldots fbox n 7 Maier Hans Huber Anna Wei8back 10 csviffirstrow then macros else macros Inside the command list of csvreader 7 the then macros are executed for the first data line and the else macros are executed for all following lines Ncsvreader tabbing head to column names table head hspace 3cm kill 7 grade csv givenname name gt csviffirstrow first entry following entry Hans Maier first entry Anna Huber following entry Werner Weifb ck following entry Maria Bauer following entry csvifoddrow then macros else macros Inside the command list of Ncsvreader 7 the then macros are executed for odd numbered data lines and the else macros are executed for even numbered lines csvreader head to column names tabular 1 1 1l1l table head hline bfseries amp bfseries Name amp bfseries Grade hline ta
43. very csv warn on column count error csv default style A style definition which is used for every following CSV file which resets all settings to default values This key should not be used or changed by the user if there is not a really good reason and you know what you do csv file file name no default initially unknown csv Sets the file name of the CSV file to be processed csv preprocessed file file name no default initially jobname_sorted csv Sets the file name of the CSV file which is the output of a preprocessor csv preprocessor macro no default Defines a preprocessor for the given CSV file The macro has to have two mandatory arguments The first argument is the original CSV file which is set by csv file The second argument is the preprocessed CSV file which is set by csv preprocessed file Typically the macro may call an external program which preprocesses the original CSV file e g sorting the file and creates the preprocessed CSV file The later file is used by csvreader P7 or csvloop P7 newcommand mySortTool 2 7 4 call to an external program to sort file 1 with resulting file 2 Ncsvreader Z preprocessed file jobname_sorted csv preprocessor mySortTool some csv 4 do something See Subsection 3 8 on page 20 for a concrete sorting preprocessing implemented with an external tool csv no preprocessing style no value initially set Clears any pr
Download Pdf Manuals
Related Search
csvsimple. csv sample file cv simple cs simple csv sample data csv sample cs simple goat csv sample file download
Related Contents
U-WAVE-R Invitation Recto Dermatix® Ultra Der Gel de silicone pour prévenir la HDMI MATRIX User Manual Viewsonic A Series VA2012wb Always here to help you Harbor Freight Tools Bench Bar and Rod Bender Product manual Installation Manual For Ezewarm Loose Wire Eglo BRIVI Copyright © All rights reserved.
Failed to retrieve file