12

What is the data structure used by spreadsheets program like ms-excel?

Zach Scrivena
  • 29,073
  • 11
  • 63
  • 73

5 Answers5

4

Maybe, probably, a sparse matrix:

http://en.wikipedia.org/wiki/Sparse_matrix

Corey Trager
  • 22,649
  • 18
  • 83
  • 121
3

I got this question in an interview today.

The answer they were looking for (because I asked the interviewer at the end) was to implement a class structure that used multiple objects; formulas, references, and numerics.

Not much more detail to offer but suffice it to say that programs like google docs are much more interesting (to code) than they seem.

Wade Williams
  • 3,943
  • 1
  • 26
  • 35
3

While it is not exactly Excel, Open Office's Spreadsheet program is open source. It's a fairly large code base but nevertheless giving it a peek might give you a better understanding of how such an application is implemented:

http://contributing.openoffice.org/programming.html

BobbyShaftoe
  • 28,337
  • 7
  • 52
  • 74
1

I expect it to use many.

For example, an AST to recalculate formulas (see this question).

Community
  • 1
  • 1
friol
  • 6,996
  • 4
  • 44
  • 81
0

Possibly a multi-dimensional array.

Bravax
  • 10,453
  • 7
  • 40
  • 68
  • 1
    That may have been the case for early spreadsheets with naive implementations that limited rows and columns to a quantity that could fit in memory, but it's doubtful any successful implementation would suffer such constraints as a 2D array would impose. The art is to give the feel of a 2D array without actually being a 2D array. – DavidO Aug 02 '15 at 15:36
  • Since someone asked me directly via email what I meant by this comment, a spreadsheet's underlying datastructure is typically a directed acyclic graph, to create a sparse array. What is seen on screen is really just the view of a traversal of the data model in a row/column order, where the row/column information is just contained within each vertex along with the payload. – DavidO Dec 25 '21 at 09:07