Simple Spreadsheet 1.0 by Alexander Tsvetkov

1. Overview

The application is a basic spreadsheet editor implemented using C# and WPF for GUI. It is intended to work on .NET Framework 4.0 as some new features of this version are used.

2. Architecture

Solution consists of four projects:
  • SimpleSpreadsheet: the UI layer
  • SimpleSpreadsheet.Core (Expressions): the core library containing the expression evaluation engine
  • SimpleSpreadsheet.Functions: an example of a library with several user functions implemented
  • SimpleSpreadsheet.Test: unit tests

Expression parsing is performed using ANTLR v.3 parser generator, original grammar file (with support of basic arithmetic expressions, functions and Excel-like cell references) can be found in /Grammar folder of .Core project. Generated lexer and parser depend on Antlr3.Runtime.dll library located in /lib solution folder.

The application itself is based on Model-View-ViewModel pattern which is quite popular in WPF world. Caliburn.Micro framework (http://caliburnmicro.codeplex.com) was chosen to provide some nice features (to be honest, only the basic functionality of this framework is used). All classes related to Caliburn are located in /Framework folder of the application project. Please note that some classes depends on System.Windows.Interactivity library, however it is not actually used by SimpleSpreadsheet. In future I am planning to fix this by removing the unnesessary dependencies.

At the moment the application displays only on worksheet, but this is just for first version: the application was designed to support several worksheets on different tabs, so this will be one of future changes. Another point of extension is custom functions: MEF is used to implement plug-in system, which allows for loading custom functions from an assembly in ./Extensions folder at application start. To import a new function, you should create a class implementing IFunction interface (located in .Core project, which serves as something like SDK or contracts assembly), mark the class for import, build the assembly and put it into ./Extensions folder in SimpleSpreadsheet's current folder. Then at startup the new function will be imported.

For effective evaliation of cell values after document load, the following techniques are used:
  • non-empty cells are divided into separate independent graphs, which allows then to evaluate these groups in parallel
  • each independent graph is topologically sorted, which allows for natural order evaluation - i.e. each cell will be avaluated only once.
(This may seem obvious, but I have seen several Excel-like engines which do not care about topological sorting and therefore sometimes reevaluate cells several times during one worksheet update.)

3. UI

The UI itself tries to mimic Excel as much as possible. Cell navigation is possible with keyboard or mouse; cells display the calculated values, while the expression in the current cell is displayed above the grid (pressing F2 moves focus to expression edit textbox). Cells can be edited by pressing letters/digits or cleared by pressing Delete. File menu allows for opening a blank document, saving the current one, or opening a document from file system (the format is rather simple: each line should match the pattern [cell address]=[expression], e.g. A1=1 or B2=A1*2 etc.).

Last edited Jun 15, 2011 at 9:21 AM by atsvetkov, version 2

Comments

No comments yet.