App-CSVUtils

 view release on metacpan or  search on metacpan

script/csv-fill-cells  view on Meta::CPAN


This utility takes values (from cells of a 1-column input CSV), creates an
output CSV of specified size, and fills the output CSV in one of several
possible ways ("layouts"): left-to-right first then top-to-bottom, or
bottom-to-top then left-to-right, etc.

Some illustration of the layout:

 % cat 1-to-100.csv
 num
 1
 2
 3
 ...
 100
 
 % csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 ; # default layout is 'left_to_right_then_top_to_bottom'
 field0,field1,field2,field3,field4,field5,field6,field7,field8,field9
 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,26,27,28,29,30
 ...
 91,92,93,94,95,96,97,98,99,100
 
 % csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout top_to_bottom_then_left_to_right
 field0,field1,field2,field3,field4,field5,field6,field7,field8,field9
 1,11,21,31,41,51,61,71,81,91
 2,12,22,32,42,52,62,72,82,92
 3,13,23,33,43,53,63,73,83,93
 ...
 10,20,30,40,50,60,70,80,90,100
 
 % csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout top_to_bottom_then_right_to_left
 91,81,71,61,51,41,31,21,11,1
 92,82,72,62,52,42,32,22,12,2
 93,83,73,63,53,43,33,23,13,3
 ...
 100,90,80,70,60,50,40,30,20,10
 
 % csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout right_to_left_then_top_to_bottom
 10,9,8,7,6,5,4,3,2,1
 20,19,18,17,16,15,14,13,12,11
 30,29,28,27,26,25,24,23,22,21
 ...
 100,99,98,97,96,95,94,93,92,91

Some additional options are available, e.g.: a filter to let skip filling some
cells.

When there are more input values than can be fitted, the extra input values are
not placed into the output CSV.

When there are less input values to fill the specified number of rows, then only
the required number of rows and/or columns will be used.

Additional options planned:

=over

=item * what to do when there are less values to completely fill the output CSV
(whether to always expand or expand when necessary, which is the default).

=item * what to do when there are more values (extend the table or ignore the extra
input values, which is the default).

=back

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--input-skip-num-lines>=I<s>

Number of lines to skip before header row.

This can be useful if you have a CSV files (usually some generated reports,
sometimes converted from spreadsheet) that have additional header lines or info
before the CSV header row.

See also the alternative option: C<--input-skip-until-pattern>.


=item B<--input-skip-until-pattern>=I<s>

Skip rows until the first header row matches a regex pattern.

This is an alternative to the C<--input-skip-num-lines> and can be useful if you
have a CSV files (usually some generated reports, sometimes converted from
spreadsheet) that have additional header lines or info before the CSV header
row.

With C<--input-skip-num-lines>, you skip a fixed number of lines. With this
option, rows will be skipped until the first field matches the specified regex
pattern.


=back

=head2 Filtering options

=over

=item B<--filter>=I<s>

Code to filter cells to fill.

Code will be compiled in the C<main> package.

Code is passed C<($r, $output_row_num, $output_field_idx)> where C<$r> is the
stash, C<$output_row_num> is a 1-based integer (first data row means 1), and
C<$output_field_idx> is the 0-based field index (0 means the first index). Code
is expected to return a boolean value, where true meaning the cell should be
filied.


=back



( run in 1.036 second using v1.01-cache-2.11-cpan-5b529ec07f3 )