Spreadsheet - how to store data on the Hard Drive?

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

1 Like

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.

3 Likes

Thanks for that.

My grid is just an array


//-----------------------------------------------------------------
// 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

:wink:

1 Like

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.

4 Likes

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

I understand the new approach, so thank you!

1 Like

for anyone interested - screenshot

2 Likes