FortuneSheet Documentation
repository·master·Indexed 24 days ago
https://github.com/ruilisi/fortune-sheetA TypeScript-based JavaScript spreadsheet library providing Excel-like functionality, including formatting, formulas, and cell manipulation. Optimized for React and Vue, it offers features such as conditional formatting, data validation, and support for Math, Text, Date, Financial, Logical, Lookup, and Dynamic Array formulas. The library includes @fortune-sheet/core and @fortune-sheet/react packages, and provides a Workbook API for programmatic control over cell values, formats, and sheet management.
What's inside FortuneSheet
- FortuneSheet is an open-source spreadsheet library designed to replace Excel functionality with a large number of commonly used spreadsheet functions. It features simple configuration to allow developers to get started with minimal setup.
Overview of FortuneSheet features
masterFortuneSheet is a JavaScript spreadsheet library providing features similar to Excel and Google Sheets, including:
- Formatting: Styling, conditional formatting, text alignment/rotation, and support for various data types (currency, percentages, dates, and custom formats).
- Cells: Drag-and-drop moving, fill handle (arithmetic/geometric sequences), multiple selection, find and replace, merge cells, and data validation (checkbox, dropdown, datePicker).
- Rows & Columns: Hide, insert, delete, and freeze rows/columns; split text to columns.
- Operations: Undo/Redo, Copy/Paste/Cut (with Excel compatibility), and Format Painter.
- Formulas & Functions: Built-in support for Math, Text, Date, Financial, Logical, Lookup, and Dynamic Array formulas (e.g.,
SUMIFS,VLOOKUP,SORT,FILTER). - Tables: Filtering (color, numerical, date, text) and multi-field sorting.
- Objects: Insert pictures (JPG, PNG, SVG) and take screenshots of selections.
Configure Filter range and conditions
masterFiltering is handled via two properties:
filter_selectdefines the range of the filter, andfilterdefines the specific conditions for each column within that range.Filter Conditions (
caljs):cellnull: Is emptycellnonull: Is not emptytextinclude: Text containstextnotinclude: Text does not containtextstart: Text starts withtextend: Text ends withtextequal: Text is exactlydateequal: Date isdatelessthan: Date is beforedatemorethan: Date is aftermorethan: Greater thanmoreequalthan: Greater than or equal tolessthan: Less thanlessequalthan: Less than or equal toequal: Is equal tonoequal: Is not equal toinclude: Is between (requiresvalue1andvalue2)noinclude: Is not between (requiresvalue1andvalue2)
// 1. Define the range "filter_select": { "row": [ 2, 6 ], "column": [ 1, 3 ] } // 2. Define conditions for column index 1 (key '0') "filter": { "0": { "caljs": { "value": "cellnull", "text": "Is empty", "type": "0" }, "rowhidden": { "3": 0, "4": 0 }, "optionstate": true, "cindex": 1, "str": 2, "edr": 6, "stc": 1, "edc": 3 } }Initialize FormulaParser in Node.js or Browser
masterTo use the parser, instantiate the
Parserclass.Node.js:
var FormulaParser = require("hot-formula-parser").Parser; var parser = new FormulaParser();Browser:
<script src="/node_modules/hot-formula-parser/dist/formula-parser.min.js"></script> <script> var parser = new formulaParser.Parser(); </script>Merge cells in FortuneSheet
masterTo merge cells, you must update both the cell objects and the sheet configuration.
- Update Cell Objects: Set the
mcattribute in the main (top-left) cell and in all other cells within the range. Themcobject requiresr(row),c(column),rs(rowspan), andcs(colspan). - Update Config: Set
config.mergeusing a key format of"r_c"(e.g.,"0_0") pointing to the samemcsettings.
Example to merge A1:B2:
Cell Data:
[ [ { "m": "merge cell", "mc": { "r": 0, "c": 0, "rs": 2, "cs": 2 } }, { "mc": { "r": 0, "c": 0 } } ], [ { "mc": { "r": 0, "c": 0 } }, { "mc": { "r": 0, "c": 0 } } ] ]Config:
{ "0_0": { "r": 0, "c": 0, "rs": 2, "cs": 2 } }- Update Cell Objects: Set the
Apply cell borders using borderInfo
masterBorders are managed via the
config.borderInfoproperty rather than the individual cell objects. To apply a border to a specific range, define theborderType,color,style, and therange(rows and columns).Example: Setting a red, solid border for cell A1:
{ "rangeType": "range", "borderType": "border-all", "color": "#000", "style": "1", "range": [ { "row": [ 0, 0 ], "column": [0, 0] } ] }Install @fortune-sheet/core
masterInstall the core spreadsheet library using npm or yarn to integrate FortuneSheet's spreadsheet capabilities into your JavaScript project.
$ npm install --save @fortune-sheet/coreor
$ yarn add @fortune-sheet/coreInstall hot-formula-parser
masterYou can install the
hot-formula-parserlibrary via NPM.Note: This repository is deprecated. It is recommended to use the HyperFormula engine instead.
$ npm install hot-formula-parser --saveImplement Backend Storage and Collaboration using Op
masterFortuneSheet supports online collaboration and backend synchronization via an
onOpcallback. This callback emits a list ofOpobjects whenever a user performs an action. EachOpdescribes the transformation required to move from the current state to the new state.Example of an
Oprepresenting a cell formatting change (e.g., setting cell A2 to bold):[ { "op": "replace", "index": "0", "path": ["data", 1, 0, "bl"], "value": 1 } ]These operations are useful for updating backend databases and synchronizing state across multiple clients.
Migrate data from Luckysheet to FortuneSheet
masterFortuneSheet is mostly compatible with Luckysheet's data structure, but requires the following naming updates:
- Change
sheet.indextosheet.id - Change
sheet.calcChain[].idtosheet.calcChain[].id(Note: The README implies a structural change or specific mapping forcalcChainIDs).
- Change
Install @fortune-sheet/react via npm or yarn
masterTo use FortuneSheet in a React project, install the
@fortune-sheet/reactpackage using npm or yarn.$ npm install --save @fortune-sheet/react # or $ yarn add @fortune-sheet/reactRender a FortuneSheet workbook in React
masterTo render a spreadsheet, ensure your container (e.g.,
#root) has a definedwidthandheight(setting them toautomay prevent the table from appearing). Import theWorkbookcomponent and its associated CSS, then pass adataarray containing sheet objects.import React from 'react'; import ReactDOM from 'react-dom'; import { Workbook } from "@fortune-sheet/react"; import "@fortune-sheet/react/dist/index.css" ReactDOM.render( <Workbook data={[{ name: "Sheet1" }]} />, document.getElementById('root') );