Skip to content

A fast, portable spreadsheet logic library

License

Notifications You must be signed in to change notification settings

gershnik/spreader

Repository files navigation

Spreader

A fast, portable spreadsheet logic library

Language Standard License

Spreader is a portable C++ library that implements spreadsheet logic - reading and writing data and formulas into cells, automatic recalculation, copying and moving cells, adding and deleting rows and columns and so on. It does not implement any spreadsheet UI, though the hope is that eventually it will be possible to write a UI based on it. It is currently in alpha stage.

Wrapper libraries in JavaScript and Python are available at spreader.js and spreader.py respectively.

Build

You will need CMake 3.24 or better as well as C++ compiler that supports C++20. The following compilers are known to work

  • GCC 11.3 or above
  • Xcode 14 or above
  • Visual Studio 2022 or above

To get the library as a dependency:

include(FetchContent)
FetchContent_Declare(spreader
    GIT_REPOSITORY [email protected]:gershnik/spreader.git
    GIT_TAG        <desired tag like v1.2 or commit sha>
    GIT_SHALLOW    TRUE
)
FetchContent_MakeAvailable(spreader)

If you have Bison 3.8 or better and/or Flex 2.6 or better available on your machine CMake build will use them to generate code for formula parser. Otherwise it will use pre-built files.

Quick start

#include <spreader/sheet.h>

using namespace Spreader;

//Create a new sheet
auto sheet = Sheet();
//Set A2 cell to contain plain value. 
sheet.setValueCell(Point{.x=0, .y=1}, "Hello ");
//You can also use regular cell notation. 
//The result of parsePoint is std::optional<Point>
sheet.setValueCell(sheet.parsePoint("B3").value(), "World!");
//Set a cell to contain formula
sheet.setFormulaCell(Point{.x=0, .y=0}, "A2 & B3");
//Read calculated formula result
auto val = s.getValue(Point{.x=0, .y=0});
//prints "Hello Wolrd!" 
std::cout << val;