Code Monkey home page Code Monkey logo

obsidian-csv-table's Introduction

Obsidian CSV Table

Have data in a CSV file that you'd like to render as a table in Obsidian? Now you can.

Quickstart

Imagine you have the following CSV file named countries.csv:

name,capitol,population
United States of America,"Washington, DC",328200000
Colombia,Bogota,50340000
Russia,Moscow,144400000

The following code block:

```csvtable
source: countries.csv
```

will render a table like:

name capitol population
United States of America Washington, DC 328200000
Colombia Bogota 50340000
Russia Moscow 144400000

Options

  • source: (Required) Path (relative to your vault's root) to the csv file to render within your notes.
  • csvOptions: Options to use for decoding the referenced CSV file; see https://csv.js.org/parse/options/ for available options.
  • columns: A list of columns to render. Each item may be either the name of a field to display or an expression (see "Expressions" below), and can be re-named. If unspecified, all columns in the referenced CSV will be rendered. See "Selecting particular columns" below for details.
  • filter: A list of filter expressions (see "Expressions" below) or a single filter expression to use for limiting which rows of the referenced CSV will be displayed. If unspecified, all rows of the referenced CSV will be rendered taking into account the value specified for maxRows below. See "Filtering displayed rows" for details.
  • sortBy: A list of sort expressions (see "Expressions" below) or a single sort expression to use for sorting the displayed rows. If unspecified, rows will be displayed in the order they appear in the referenced CSV. See "Sorting Rows" for details.
  • columnVariables: A mapping of variable name to column name allowing you to set a name for use in filter or columns above to reference the value of a field that is not a valid variable name.
  • maxRows: The maximum number of rows to display. If unspecified, all unfiltered rows of the referenced CSV will be displayed.

Expressions

This library uses filtrex for expression evaluation; see their documentation to see more information about the expression syntax and what functions are available: https://github.com/m93a/filtrex#expressions.

See "Filtering displayed rows" for an example of a filter expression in action, but realistically they work exactly as you'd probably expect.

Selecting particular columns

You can use the columns field to control which columns of your CSV file to render, e.g:

```csvtable
columns:
- name
- population
source: my_csv_file.csv
```
name population
United States of America 328200000
Colombia 50340000
Russia 144400000

It's also possible for you to set better names for your columns or use expressions:

```csvtable
columns:
- expression: name
  name: Country Name
- expression: population  / 1000000
  name: Population (Millions)
source: my_csv_file.csv
```
Country Name Population (Millions)
United States of America 328.2
Colombia 50.34
Russia 144.4

Filtering displayed rows

Maybe you would like to display only a subset of the rows of your CSV? If so, you can provide a filter expression to limit which rows are shown:

```csvtable
source: my_csv_file.csv
filter: population < 100000000
```
name population
Colombia 50340000

By default, the parser will attempt to cast the values of each field to an integer, boolean, or date object where appropriate for use in your filter expressions. Also, note that your filter expression can also be provided as a list; those expressions will be and-ed together, e.g.:

```csvtable
source: my_csv_file.csv
filter:
- population < 100000000
- name == "Colombia"
```

Note that the filtering language requires that you use double-quoted strings in comparisons -- if you had entered name == 'Colombia' above, the filter would not have returned results.

Sorting Rows

If you would like to sort the rows of your displayed CSV, you can provide a sort expression:

```csvtable
source: my_csv_file.csv
sortBy: name
```
name population
Colombia 50340000
Russia 144400000
United States of America 328200000

Additionally, you can specify your sortBy expression as a list; the document will be sorted by all specified fields in rank order:

```csvtable
source: my_csv_file.csv
sortBy:
- columnOne
- columnTwo
```

It's also possible for you to sort your displayed data in reverse order if you specify your sortBy expression using an extended format allowing you to specify both the expression and direction of sort:

```csvtable
source: my_csv_file.csv
sortBy:
- expression: name
  reversed: true
```
name population
United States of America 328200000
Russia 144400000
Colombia 50340000

obsidian-csv-table's People

Contributors

coddingtonbear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

obsidian-csv-table's Issues

export from Outlook gives error when trying to read

I export my contacts from outlook to a csv. When the plugin tries to read it gives an error because the header has 96 fields and a record has less. It is not illegal to have a short line in a csv. It means to treat the rest of the fields are empty.

Filter by element in array

I have a table with cells acting pretty much like arrays ("Type" column):

Score Activity Type
99 Trading Hobby, Business, Guild, Quests
90 Apothecary Hobby, Quests
85 Herbalist Hobby, Quests

I would like to have a filter something like this:

filter: Type.includes('Hobby')

or like this:

filter: 'Hobby' in Type

I.e. not an exact match, but it should include the element.

Date time filter

Hi.. how can I apply a filter in a timestamp column dinamically?

CSV sample:

Subject,start,end,duration,Organizer
meeting 1,2021-01-11 08:00,2021-01-11 12:00,240,[email protected]
meeting 2,2021-01-11 08:00,2021-01-11 12:00,240,[email protected]
meeting 3,2021-01-11 16:00,2021-01-11 17:00,60,[email protected]
meeting 4,2021-01-12 10:00,2021-01-12 11:00,60,[email protected]
meeting 5,2021-10-28 12:00,2021-10-28 13:00,60,[email protected]

``csvtable
columns:

  • Organizer
  • Subject
  • start
  • duration
  • end
  • RequiredAttendees
    source: calendar.csv
    filter:
  • start >= "[[2021-10-28]]"
  • start <= "[[2021-10-28]]"
    sortBy: start

in this sample just the meeting 5 should be returned:
meeting 5,2021-10-28 12:00,2021-10-28 13:00,60,[email protected]

the start and end date should be defined based  on the current date.

CSV file 'xyz.csv' could not be found.

Do you have any kind of logs I could turn on and check? Whatever I do I get the error message in the title. The plugin is definitely able to work (it did when I installed it in an empty vault) but it does not when I install it in my own vault. I disabled all the other plugins to filter out interference but it still refused to yield. I suspect vault path is the culprit but am at a loss here.

More a question than an issue. refresh and movement of files

First of all. Thanks for your work. It helps a lot to use csv with an application like "Modern CSV" in Obsidian.

refresh

If I'm working on the csv from within Obsidian, changes are not visible until I close and reopen the document.
Is there any way to do this automatically or via some sort of command provided by you?

movement of files

I'm working with the PARA method from Tiago Forte. After completing a project (which is a single markdown file with links to various attachments in an attachement folder incl csv which are used in csvtable ) this project file is moved to an archive folder. The attachement is moved automatically to the attachement folder of the archive (plugin "consistent attachments and links"). The "link" in csvtable is not changed accordingly. Would it even be possible to implement such a feature?

Add a "run" button to allow code flow when reading

I use your excellent plugin together with the execute code plugin, and thus I would find it useful to have a "run" button to allow for running the commands in csvtable when in reading mode (so that if the code above modifies the csv file, we can see the mods)and it would make your plugin even more awesome and useful.

Can't convert csv file into table when separator is semicolon

Hello,

I have this file which is delimiter is semicolon ";".

a;b;c
1;2;3

I'm using following code but without avail:

csvOptions:
- delimiter: ';'

source: random.csv

image

I've tried also changing single quotes around semicolon into double quotes and over various things, but still, no progress.

It works well if you change the delimiter in the file itself to ",".

Could please point me to right direction how can I make it to working with semicolon? Thanks.

Table not rendered in slide show

The table does not get rendered when in slideshow/presentation mode although it gets rendered perfectly well when being displayed in normal markdown view.

Is there something special that needs to be done for slideshows?

File path relative to current note

Hi,

Thanks for creating and maintaining this much-needed plugin. Unfortunately, I am unable to use it because of the requirement that the source path must be relative to the vault's root. (In other words, it's an absolute path from the vault's perspective.)

I would rather like to set the path relative to the current note.
For example, if my note's attachments reside in folder files below the current folder, the source: value should be files/table.csv (or maybe ./files/table.csv, to distinguish it from paths relative to the vault's root).

Reason:

With a path relative to the vault's root, if I move the note and its attachment folder to another folder, the source path breaks.

A path relative to the current note would survive any note rearrangements, as long as the relative path to the note's attachments does not change.

Recognize wikilinks

It would be great if this plugin could render the contents of the csv in a way so that Obsidian could recognize (and allow clicking) the wikilinks in it. Having a wikilink in a row anywhere but the last column will not render that row at all. Having it in the last column will show it as plain text.

Parse wiki-links

Cell values like [[Some page]] should turn into links – that would be a killer-feature.

Mobile support?

Hey there, just wondering if you're planning to support Mobile? Both of my Android devices report "Failed to load plugin obsidian-csv-table" whe I attempt to enable. Thanks!

Error evaluating filter expressions

Hello,
My cvs file contains the items below:

"Nom","Localité"
"Zoé","Paris"
"Léa","Lyon"

In the source file, I wrote:

csvtable
columns:
	- Nom
	- Localité
source: contact/export.csv
filter: Localité == "Paris"

If the column name to be filtered contains accents, the following error is encountered:

Error evaluating filter expressions: Lexical error on line 1. Unrecognized text.
Localité == "Paris"
-------^.

I have tried with single and double quotes, but it does not work.

Could not parse CSV table spec: Unexpected scalar at node end at line 6, column 10:

filter: "Localité" == "Paris"
         ^

The accents are not a problem in the values, it matches correctly:

filter:  Nom == "Zoé"

csvOptions help

Hello,
I don't understand how to use the csv options to change the delimiters, I would like some help.

My cvs file contains the items below:

"Nom";"Localité"
"Zoé";"Paris"
"Léa";"Lyon"

In the source file, I wrote:

csvOptions: delimiter: semicolon
source: contact/test-csvoption.csv

or

csvOptions: delimiter: ;
source: contact/test-csvoption.csv

or

csvOptions: delimiter: ";"
source: contact/test-csvoption.csv

I get this error :

Could not parse CSV table spec: Nested mappings are not allowed in compact mappings at line 1, column 13:
csvOptions: delimiter: semicolon

and with this source code

delimiter: semicolon
source: contact/test-csvoption.csv

or

delimiter: ;
source: contact/test-csvoption.csv

or

delimiter: ";"
source: contact/test-csvoption.csv

I get this error :

Invalid Closing Quote: got ";" at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment

Support links inside table

Hi there,

I've started using tables more heavily in Obsidian. I would love to use your plugin, but I use a lot of links inside my tables. Unfortunately these are not displayed as clickable links when obsidian-csv-table parses them. Any chance this could be included?

Thanks :)

Cannot load file in some subdirectory

The file can be shown if it is put under the root of the vault path.
However, if I create a subdirectory (i.e. "assets") and put the csv file into it, the plug in cannot load it properly.
Is it because of my OS's default language?

スクリーンショット 2023-05-24 103410

use relative path for csv file

how about allowing specifying relative path for csv file (relateive to the markdown file rendering it)

like

```csvtable
source: ./relative/path/to/file.csv
```

csv file 'xxxxx.csv' could not be found

Hi,
I recently installed your plugin, but no matter where I put my CSV file, I have the same error: CSV file 'xxxxx.csv' could not be found.
I have Obsidian V0,13.6 on windows 11 (Build 2021.11.21.25838867)

Hot-reload csv

Listen to file changes and reload the data automatically.

I've forked your repository to add support for markdown tables as an additional source option

Hi

Love your plugin .. it solved a lot of issues for me and its so simple to use. It would be good to see it as a community plugin.

I've have forked your repository (https://github.com/adxsoft/obsidian-csv-table) however so I could add support for markdown tables to also be a source for rendering tables - strictly for my own purposes. I've tried to ensure that it does not clash with your plugin in any way. Feel free to see if what I have done interests you. If so I would be happy to convert to a pull request.

Kind Regards
Allan@adxsoft

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.