# Trouble with saving to Table

**URL:** https://discourse.processing.org/t/trouble-with-saving-to-table/10150
**Category:** Coding Questions
**Created:** [April 9, 2019, 10:28pm UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150 "2019-04-09T22:28:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [April 9, 2019, 10:28pm UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/1 "2019-04-09T22:28:48Z")

</div>

I am trying to make an interface that would save grades for students. Then the data is saved to CSV.  
In the first column I have the student ID (SID)- next to it are the grades.

 ![Table](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7c2118c34e74ab5475bb5c88cb361879e1a194d1.png)

What I wish for is that if I go back to the Student ID 202 for instance, and enter new grades, I wont have processing make a new row later, I can actually re-write the grades on row 2.

So is there a way to specify where in the spreadsheet I would be writing the rows?

Thanks a lot,

Here is my code:

```auto
void SaveToFile ()

{
  TableRow newRow = table.addRow();
 
  newRow.setInt("SID", SID);
  newRow.setInt("outline", outline);
  newRow.setInt("internal", internal);
    newRow.setInt("retention", retention);
  newRow.setInt("marginal", marginal);
  newRow.setInt("impression", impression);
  ////////////////////////
    newRow.setInt("surf", surf);
  newRow.setInt("margins", margins);
   newRow.setInt("occlusion", occlusion);
  newRow.setInt("contour", contour);
   newRow.setInt("lab", lab);

  
  saveTable(table, "data/YepuGrades.csv");
  println("Settings Saved");

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 10, 2019, 12:54am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/2 "2019-04-10T00:54:08Z")

</div>

[Processing.org/reference/Table\_findRow\_.html](http://Processing.org/reference/Table_findRow_.html)

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [April 17, 2019, 10:52pm UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/3 "2019-04-17T22:52:21Z")

</div>

Thanks for the guidance. However, FindRow is finding a row in a table already written.  
I am looking to write new rows, and re-write them over the old values.

Sorry, I am new.

Can you help?

Thanks

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 17, 2019, 11:44pm UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/4 "2019-04-17T23:44:29Z")

</div>

> [@laptophead](#):
>
> I am looking to write new rows,

> **[addRow() / Reference](https://processing.org/reference/Table_addRow_.html)**
>
> Use addRow() to add a new row of data to a Table object. By default, an empty row is created. Typically, you would store a reference to the new row in a TableRow object (see ne…

> [@laptophead](#):
>
> , and re-write them over the old values.

> **[getRow() / Reference](https://processing.org/reference/Table_getRow_.html)**
>
> Returns a reference to the specified TableRow. The reference can then be used to get and set values of the selected row, as illustrated in the example above.

> **[TableRow / Reference](https://processing.org/reference/TableRow.html)**
>
> A TableRow object represents a single row of data values, stored in columns, from a Table. Additional TableRow methods are documented in the

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 18, 2019, 12:01am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/5 "2019-04-18T00:01:45Z")

</div>

> [@laptophead](#):
>
> What I wish for is that if I go back to the Student ID 202 for instance, and enter new grades, I wont have processing make a new row later, I can actually re-write the grades on row 2.

> [@laptophead](#):
>
> I am looking to write new rows

I think I’m confused. Do you want a new row, or not? I thought you wanted to edit an old row.

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [April 18, 2019, 6:19am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/6 "2019-04-18T06:19:59Z")

</div>

I am sorry, maybe I wasnt clear.

I would want to re-write a row in a predetermined place.  
So lets say the student 202 should always be on row 2 and when I change the grades, he’s new grades are written again on row 2.  
Right now, a new row would be added. That means that he’ll have multiple entries on the sheet.  
Thanks

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 18, 2019, 6:22am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/7 "2019-04-18T06:22:49Z")

</div>

Use findRow

Then you have a row object

Here you can change the old data

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [April 18, 2019, 6:50am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/8 "2019-04-18T06:50:03Z")

</div>

I understand the part about finding the row.  
But then how do I write on that particular row?  
If use " ```  
newRow.setInt( etc

```auto
That would make me a new row at the bottom of the sheet.
Thanks
```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 18, 2019, 6:56am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/9 "2019-04-18T06:56:31Z")

</div>

Table::**findRow()**, Table::**getRow()**, Table::**addRow()**, etc. methods all return a TableRow object. 🏟

You then change that returned TableRow object using its own methods, not those from Table: 🤓  
[Processing.org/reference/TableRow.html](http://Processing.org/reference/TableRow.html)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 18, 2019, 8:07am UTC](https://discourse.processing.org/t/trouble-with-saving-to-table/10150/10 "2019-04-18T08:07:33Z")

</div>

Exactly

Don’t use addRow obviously

Use findRow and then  
row.setFloat(“mass”, 15.9994);  
row.setString(“name”, “Oxygen”);
