Skip to content Skip to sidebar Skip to footer

Creating A Spreadsheet

I have an application I'm building that is basically just an online spreadsheet. I've been wondering how I should start building this. My primary tech stack is with Rails, but I ca

Solution 1:

If "columns" are a core part of your problem domain then it may be useful to create a table to store them. Spreadsheets usually have tables, columns, rows, and cells with well defined relationships between them (cells belong to columns and rows, columns and rows belong to tables). That seems like a natural fit to a relational data store like MySql.

You could create a table for your column definitions which contains the index of each column, a foreign key to the table it belongs to, and the user-specified display name for that column.

Solution 2:

I would go with storing them as CSV files on your server or just having a table in MySQL with one additional column with the CSV text. Since it seems like the only data your users will be putting in their spreadsheet will be text, you will not have to worry about fields being too large.

Solution 3:

Using Rails and ActiveRecord, you could have the following models for your app:

classTable < ActiveRecord::Base #attributes - name:string
  has_many :columnsendclassColumn < ActiveRecord::Base #attributes - name:string, number:integer, table_id:integer
  has_many :rows
  belongs_to :tableendclassRow < ActiveRecord:: Base#attributes - number:integer, value:text, column_id: integer
  belongs_to :columnend

So creating a column called 'Revenue' which is going to be the first column in an excel sheet will translate to something like this in ActiveRecord:

@table.columns.create(name: "Revenue", number: 1)

You could then add a row with a value of '$1000' to that column like this:

@table.columns.find(1).rows.create(value: "$1000")

Hope that helps!

Post a Comment for "Creating A Spreadsheet"