Table of Contents

CSV Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Display CSV as table

Last updated on
2022-01-03
Provides
Syntax
Repository
Source

Tagged with csv, file, tables

This plugin was originally written by Steven Danz. The current version fixes security bugs and incorporates several patches by other contributors.

Description

A CosmoCode Plugin

This is a simple plugin that will display CSV data in table form. The data can either be inline between <csv> and </csv>

<csv>
Number,Name,Details
1,Power Man,Blue
2,Red Book,"Yellow, but blue"
</csv>

or be read from a file in the media area using

<csv namespace:test.csv></csv>

You can also give an HTTP URL to a CSV file instead of an uploaded media file.

If you are planning to use csv files in the media area, you will most likely need to include the .csv file extension in mime.local.conf so you can upload .csv files. Something like this should get you started:

mime.local.conf
csv     text/csv

The <csv> tag allows for additional options to be specified as well as a file reference.

Option Description Default value
file=<filename> where <filename> can be any <namespace:file.csv> or <http url>. The file= prefix is optional. Any option without a name is assumed to be the file name
hdr_rows=<n> Format the first <n> rows of data from the CSV as column headers 1
hdr_cols=<n> Format the first <n> columns of each row as column headers 0
span_empty_cols=[01] Create colspans for each empty (two adjacent commas) cell following a cell with content 0
delim=<char> The delimiter used between cells. Specify tab for a tab separated file. ,
maxlines=<n> limiting the result set to a certain number of rows 0
offset=<n> skipping the given number of rows before output 0
filter[<n>][t]="<text>" Allows you to filter the rows.

<n> is the column number you want to filter on. The first column is 1.

t can either be an g for globbing or an r for regexp. Use simple * in the globbing mode to find partial texts.

Cells that include a comma as part of the data are expected to be contained between double quotes, which is the typical behaviour of most systems when exporting .csv files.

Empty lines in the csv file or data are displayed as horizontal separators in the table.

Example for a table using a filter. This will look for values beginning with “P” in the third column. It will show the second line.

<csv hdr_rows=0 filter[3][g]="P*">
ABC,DEF,GHI
JKL,MNO,PQR
</csv>

There is a second syntax mode to grab a single value from a CSV. This mode does not support inline CSV data!

<csvval some.csv output=3,1>

In addition to all the options supported in the <csv> syntax, you have to specify which column and (optionally) which row you want to output.

Download

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Changes

Enhancement Considerations

Use with a Google Docs Spreadsheet

The HTTP URL can be a shared Google Docs Spreadsheet. The following explains how to export a spreadsheet in CSV format via a URL.

To link to a Google spreadsheet:

Outline of steps adapted from: