# Spreadsheet - how to store data on the Hard Drive?

**URL:** <https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733>\
**Category:** Beginners\
**Created:** [February 9, 2025, 9:53am UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733 "2025-02-09T09:53:35Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [February 9, 2025, 9:53am UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/1 "2025-02-09T09:53:35Z")

</div>

Hello all!

I wrote a Spreadsheet like Excel.

Data is stored as a `Table` on the Hard Drive and for displaying it on the screen and to use the mouse in the cells, I use a grid of a `class Cell`.

There are text, numbers or formulas (all stored in the Table as `String`) and results of the calculations are stored in the grid (on the fly, not on Hard Drive).

My question is when I want to _format cells_ (textSize, background color of the cell…) where / how can I store this permanently on the Hard Drive?

My thoughts:

1. The Table itself doesn’t have extra fields for it. Bad. I could “hack” a field and write multiple data in one cell like #text#backgroundColor#textSize# and parse it (use `split()` with “#”) after loading and display only the text and use the data. Seems cumbersome.
2. I could have and save a parallel 2nd table backgroundColor and 3rd table textSize and load them all together. Seems cumbersome.
3. Or I write a new data structure, a special table where only the cells with other than standard formatting are stored like x,y,backgroundColor,textSize as Table / csv.

What are your thoughts?

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 9, 2025, 1:41pm UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/2 "2025-02-09T13:41:26Z")

</div>

I wouldn’t recommend options 2 & 3 because you you have to synchronize actions for all tables, so if you delete a row in one table you must delete the same row in any other table. Same for insert etc.

Option 1 seems more reasonable because you could define all the table cells as string and like you said encode the data as `value#format_string` where `format_string` encodes the format to be applied.

After looking at the source code and reference it seems that the `Table` structure can only handle cells containing strings or primitive data types. It is a shame `Table` does not support user defined classes but it would have increased the complexity of the source code.

I have never used `Table` before so what follows may not be possible.

I would create new classes that extend `Table` and `TableRow` the extended row class would store objects of a new class called `TableCell`. The cell class would store value and format data and then do the encoding to store it in the underlying `Table` structure. Sounds straight forward but would be very challenging to implement. Basically its an extension of option 1.

---

<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:** [February 9, 2025, 1:45pm UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/3 "2025-02-09T13:45:58Z")

</div>

Thanks for that.

My grid is just an array

```auto

//-----------------------------------------------------------------
// Table, grid, ArrayLists, vars...

// The table
Table myTable;

// graphically myTable is represented with a grid
Cell[][] grid;

```

It is a shame that we cannot say

`saveArray (grid);` - same for `ArrayList`

😉

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 9, 2025, 4:05pm UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/4 "2025-02-09T16:05:26Z")

</div>

I assume `Cell` is a class you have created, am I correct?

Actually the solution might be easier. `TableRow` is an interface so you sim[ly need to create a class that implements this interface and that class can perform the encoding / decoding values and format.

---

<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:** [February 11, 2025, 10:44pm UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/5 "2025-02-11T22:44:35Z")

</div>

> [@quark](#):
>
> I assume `Cell` is a class you have created, am I correct?

That is correct. It’s a cell in the grid that visualizes the Table.

> [@quark](#):
>
> `TableRow` is an interface so you sim[ly need to create a class that implements this interface and that class can perform the encoding / decoding values and format.

I understand the new approach, so thank you!

---

<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:** [February 17, 2025, 1:04pm UTC](https://discourse.processing.org/t/spreadsheet-how-to-store-data-on-the-hard-drive/45733/6 "2025-02-17T13:04:19Z")

</div>

for anyone interested - screenshot

 ![Unbenannt](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/5/e53b5f987f633ee6dfbac0610bb4ca64b571718d.png)
