# Savetable with P5

**URL:** https://discourse.processing.org/t/savetable-with-p5/17475
**Category:** p5.js
**Created:** [January 31, 2020, 9:44am UTC](https://discourse.processing.org/t/savetable-with-p5/17475 "2020-01-31T09:44:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jp3001](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@jp3001](https://discourse.processing.org/u/jp3001)
#### Post date: [January 31, 2020, 9:44am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/1 "2020-01-31T09:44:41Z")

</div>

I’ve got a strange error when trying to save a p5.table

tablo= new p5.table;  
saveTable(tablo,‘Memory’,‘csv’);

I’ve got the following msg:  
Exception has occured  
Error: creaheader is not defined

but if I enter ‘html’ instead of ‘csv’ everything is working file and the table is save in the file !!

Pls help !

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 31, 2020, 4:55pm UTC](https://discourse.processing.org/t/savetable-with-p5/17475/2 "2020-01-31T16:55:28Z")

</div>

so possibly empty files are not allowed?  
need minimum a table structure to make a header line

[https://editor.p5js.org/kll/sketches/Ie48wONx](https://editor.p5js.org/kll/sketches/Ie48wONx)

* * *

but usually start the other way, from reading a file  
-a- create in online editor a subdirectory  
/assets/  
-b- create inthere a new file ‘Memory.csv’  
edit it manually with 2 lines minimum,  
one header line  
one data line

(or upload the file from you computer )

and in your code just use  
[https://p5js.org/reference/#/p5/loadTable](https://p5js.org/reference/#/p5/loadTable)

```auto
function preload() {
  table = loadTable('assets/Memory.csv', 'csv', 'header');
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [January 31, 2020, 5:02pm UTC](https://discourse.processing.org/t/savetable-with-p5/17475/3 "2020-01-31T17:02:18Z")

</div>

Hello,

I used this example:

[https://p5js.org/reference/#/p5/saveTable](https://p5js.org/reference/#/p5/saveTable)

I edited it:

```auto
let table;

 function setup() {
 table = new p5.Table();

// table.addColumn('id');
 //table.addColumn('species');
 //table.addColumn('name');

 //let newRow = table.addRow();
// newRow.setNum('id', table.getRowCount() - 1);
 //newRow.setString('species', 'Panthera leo');
// newRow.setString('name', 'Lion');

 // To save, un-comment next line then click 'run'
  saveTable(table, 'new.csv');
 }

 // Saves the following to a file called 'new.csv':
 // id,species,name
 // 0,Panthera leo,Lion

```

It saves a csv file.

This works as well:

```auto
 saveTable(table, 'new', 'csv');

```

Google Chrome was used along with [https://editor.p5js.org/](https://editor.p5js.org/)

---

<div class="post-metadata">

### Author: ![jp3001](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@jp3001](https://discourse.processing.org/u/jp3001)
#### Post date: [February 3, 2020, 9:33am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/4 "2020-02-03T09:33:47Z")

</div>

My table is not empty I am entering valus as follows ::

tablo = new p5.Table();

tablo.addColumn(‘search\_key’);

tablo.addColumn(‘counter’);

```
 newRow = tablo.addRow();

newRow.setString('search_key', key_search + "\t");

newRow.setNum('counter', counter);
```

---

<div class="post-metadata">

### Author: ![jp3001](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@jp3001](https://discourse.processing.org/u/jp3001)
#### Post date: [February 3, 2020, 9:38am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/5 "2020-02-03T09:38:24Z")

</div>

The strange thing is when I saved the table using :

saveTable(tablo,‘Memory’,‘csv’); I’ve got the error msg

but if I save with:

saveTable(tablo,‘Memory’,‘html’);

the save is saved perfectly !

This strange behaviour is the reason of this post

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [February 4, 2020, 2:06am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/6 "2020-02-04T02:06:32Z")

</div>

so, you see that you got 2 answers what all say:

```auto
saveTable(table, 'filename.csv', 'csv');

```

or

```auto
saveTable(table, 'filename.csv');

```

works,  
using the online editor,  
( i give you already the link to my test code)  
but again minimal test what works:

```auto
let table = new p5.Table();

function setup() {
  saveTable(table,'Memory','csv');
}

```

and in my case using win 10 / firefox browser

* * *

why you not just give us the link to your  
project in the online editor so we can reproduce that error.

---

<div class="post-metadata">

### Author: ![jp3001](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@jp3001](https://discourse.processing.org/u/jp3001)
#### Post date: [February 4, 2020, 10:00am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/7 "2020-02-04T10:00:47Z")

</div>

I finally found the error : the p5.js library file was corrupted !  
Now everything is working fine

Thanks to all of you

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [February 4, 2020, 11:27am UTC](https://discourse.processing.org/t/savetable-with-p5/17475/8 "2020-02-04T11:27:40Z")

</div>

> [@kll](#):
>
> so, you see that you got 2 answers what all say:
> 
> ```auto
> saveTable(table, 'filename.csv', 'csv');
> 
> ```
> 
> or
> 
> ```auto
> saveTable(table, 'filename.csv');
> 
> ```
> 
> works,  
> using the online editor,

I posted [these examples](https://discourse.processing.org/t/savetable-with-p5/17475/3) along with this [reference](https://p5js.org/reference/#/p5/saveTable):

```auto
saveTable(table, 'new.csv');

Or:
saveTable(table, 'new', 'csv');

Will save a table as:
new.csv

```

```auto
And adding this:
saveTable(table, 'new.csv', 'csv');

```

So there are 3 ways to save the table to:  
`new.csv`

’ 🙂 ’
