CSV to html – Choosing files

The source_type attribute defines what kind of structure the fetched file(s) has. visualizer_plugin is set as default. This is because the plugin was made for that format from the beginning (Initially this plugin was made for generating tables from charts fething data from the Visualizer Plugin (https://wordpress.org/plugins/visualizer/). If you are having problem fetching the data – try to to use ”guess” instead (it’s a more ordinary case to use guess).

Valid source types:
  • guess
  • json
  • visualizer_plugin
  • (Visualizer plugin) example data:
  • ,Sweden
  • 2010,number
  • 2011,"1.6%"
  • 2012,"2.2%"
  • 2013,"3.2%"
  • 2014,"4.5%"
  • 2015,"6.9%"

Shortcode
[csvtohtml_create source_type="visualizer_plugin" path="csvfiles" source_files="sweden.csv"]
path defines relative path from the servers upload-folder (e.g. wp-content/uploads/csvfiles).
If path is not defined, then wp-content/uploads is used.

20112012201320142015
Sweden1.6%2.2%3.2%4.5%6.9%

Combine files

If you want to have data from serveral files into one table, just add them in the source_files separated with a semicolon.

Shortcode
[csvtohtml_create source_type="visualizer_plugin" path="csvfiles" source_files="sweden.csv;norway.csv;finland.csv"]
20112012201320142015
Sweden1.6%2.2%3.2%4.5%6.9%
Norway-6.6%1.2%1.4%1.9%2.0%
Finland-16.6%-14.2%10.2%11.0%13.2%

Combine files into one table with a ”wildcard”.

If you want to have data from serveral files into one table, just add the wildcard, like *.csv or *.*. This is only applicapble when dealing with csv-files locally (on the webserver where your site is stored). If any files are added to the given path, those files are included in the generation of the table. (The reason why Sweden is shown twice below is that there are two files with identical data on this server in the csv-files folder (sweden.csv and sweden_mac.csv))

Shortcode
[csvtohtml_create source_type="visualizer_plugin" path="csvfiles" source_files="*.csv"]
20112012201320142015
Denmark-2.6%0%2.6%2.9%2.11%
Finland-16.6%-14.2%10.2%11.0%13.2%
Iceland6.6%6.2%7.2%11.0%16.2%
Norway-6.6%1.2%1.4%1.9%2.0%
Sweden1.6%2.2%3.2%4.5%6.9%
Sweden2010

External files

With CSV to HTML it is also possible to fetch data from external files (the files does not have to be on your own server). Down below is actually a mix of an external file (https – sweden) and internal files (norway,finland,iceland,denmark):

Shortcode
[csvtohtml_create source_type="visualizer_plugin" path="csvfiles" source_files="https://wibergsweb.se/wp-content/uploads/csvfiles/sweden.csv;norway;finland;iceland;denmark"]
20112012201320142015
Sweden1.6%2.2%3.2%4.5%6.9%
Norway-6.6%1.2%1.4%1.9%2.0%
Finland-16.6%-14.2%10.2%11.0%13.2%
Iceland6.6%6.2%7.2%11.0%16.2%
Denmark-2.6%0%2.6%2.9%2.11%

It’s also possible to fetch google sheets if adding some attributes to the url and setting an attribute for the shortcode (add_ext_auto). This add_ext_auto adds the file extension .csv as default. When dealing with google sheets (or maybe some other source) you don’t want any file extension to be added.

Shortcode
[csvtohtml_create source_type="guess" add_ext_auto = "no" source_files="https://docs.google.com/spreadsheets/d/{key}/gviz/tq?tqx=out:csv&sheet={sheet_name}"]

There are no preview for this because google sheet’s specification how to achieve this usually do change over time. Please take a look at https://stackoverflow.com/questions/33713084/download-link-for-google-spreadsheets-csv-export-with-multiple-sheets for some ideas how to fetch your google sheets document as a csv file.