Coder Social home page Coder Social logo

ruilisi / fortune-sheet Goto Github PK

View Code? Open in Web Editor NEW
2.2K 26.0 200.0 3.38 MB

A drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets

Home Page: https://ruilisi.github.io/fortune-sheet-docs/

License: MIT License

JavaScript 9.73% HTML 0.01% TypeScript 88.45% Yacc 0.20% CSS 1.61%
excel javascript react spreadsheet xlsx collaborative typescript datagrid

fortune-sheet's Introduction

FortuneSheet

FortuneSheet is a drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets

CircleCI Status Known Vulnerabilities Build with father xiemala

English | 简体中文

Purpose

The goal of FortuneSheet is to make a feature-rich, easy-to-configure online spreadsheet that you can use out-of-the-box.

This project is originated from Luckysheet and has inherited many code from it. Lots of efforts have done to translate the whole project to typescript (still in progress), and solved problems in the design of the original project.

We aim to make FortuneSheet powerful yet easy to maintain.

Communication

Live demo

Take a look at the live demo at fortune-sheet-demo

Attention

Before stable release of 1.0, input data structure and APIs may change during development. If you encounter errors after upgrading a version, check Changelog and Migration Guide.

Improvements to Luckysheet

  • Written fully in typescript.
  • You can now use import / require to use the library.
    import { Workbook } from '@fortune-sheet/react'
  • Multiple instance on the same page is supported.
  • Dropped jQuery dependency, uses native React / Vue + immer to manage the dom and state.
  • Changed to a forked handsontable/formula-parser to handle formula calculations.
  • Optimized the dom structure.
  • Replaced icons from iconfont with SVGs, as iconfont icons are inconvenient to update for other maintainers.
  • No visible elements is created outside container.
  • Never stores data in the window object.

Features

  • Data structure is mostly compatible with Luckysheet (see Migration Guide).
  • Formatting: style, text alignment and rotation, text truncation, overflow, automatic line wrapping, multiple data types, cell segmentation style
  • Cells: multiple selection, merge cells
  • Row & column: insert, delete rows or columns
  • Operation: copy, paste, cut, hot key
  • Formulas & Functions: Built-in formulas

Roadmap

  • ✅ Support cooperative editing with backend storage.
  • ✅ Support undo/redo.
  • ✅ Mobile adaption.
  • ✅ Expose APIs.
  • ✅ Add tests.
  • More basic features:
    • ✅ fill handle
    • ✅fonts
    • ✅ format painter
    • ✅ comments
    • ✅ insert images
    • ✅ more toolbar buttons
  • Excel import and export.
  • Support Vue.
  • More features:
    • ✅ sort
    • ✅ filter
    • ✅ hooks
    • ✅ conditional formatting
    • ✅ drag and drop
    • ✅ find and replace
    • location
    • ✅ data verification
    • ✅ freeze
    • ✅ hide, and split text
  • More advanced features:
    • pivot tables
    • charts
    • ✅ screenshots

Documentation

See detailed documentation at fortune-sheet-doc

Get started (react)

Download and install the library

Using npm
npm install @fortune-sheet/react
Using pnpm
pnpm install @fortune-sheet/react
Using yarn
yarn add @fortune-sheet/react

Create an HTML placeholder

<style>
  html, body, #root {
    width: 100%;
    height: 100%;
  }
</style>
<div id="root"></div>

NOTE: width and height doesn't have to be 100%, but should at least have a value. If set to auto, table area may not show.

Render the sheet

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')
);

Backend storage and collabration

Each time a user operates on the sheet, an array of Op will be emiited through onOp callback. An op describes how to modify the current data to reach the new data after the user's operation. For example, here is an op when user sets the cell font to be bold on cell A2.

[
    {
        "op": "replace",
        "index": "0",
        "path": ["data", 1, 0, "bl"],
        "value": 1
    }
]

The op is useful for database modification and syncing state in online collabration.

A working example with Express (backend server) and MongoDB (data persistence) is avaiable in backend-demo folder.

Run it with node index.js and visit Collabration example (initialize data by visiting http://localhost:8081/init)

For detailed doc about Op, refer to fortune-sheet-doc

Migrating data from Luckysheet

The overall data structure of FortuneSheet is the same as Luckysheet, with some naming differences:

  1. sheet.index -> sheet.id
  2. sheet.calcChain[].id -> sheet.calcChain[].id

Contributing

Expected workflow is: Fork -> Patch -> Push -> Pull Request

Please make sure to read the Contributing Guide before making a pull request.

Development

Installation

yarn

Development

yarn dev

Packaging

yarn build

License

This project is licensed under the MIT License. See MIT for the full license text.

fortune-sheet's People

Contributors

baian1 avatar cybermerlin avatar czsandszs avatar fossabot avatar gazedreamily avatar gazewilly avatar gudipudipradeep avatar hophacker avatar igeligel avatar jearyvon avatar jikoczl avatar lvjing-tuzhi avatar qaplagzy avatar sanchit3008 avatar shuanhukexuejia avatar sukels avatar valpackett avatar zhcalvin avatar zhengice avatar zyc9012 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fortune-sheet's Issues

Read Only (and a strange error in the console)

Describe the bug
I'm looking for how to display an excel file in ready only mode - without any edition

To Reproduce
I open the file using LuckExcel, directly from an URL with LuckyExcel.transformExcelToLuckyByUrl
Then I load the result with the following:

let options = {
          container: 'react-excel-id', //react-excel-id
          showinfobar: false,
          showsheetbar: true,
          data: exportJson.sheets,
          enableAddRow: false,
          row: 26,
          column: 26,
          allowUpdate: false,
          enableAddBackTop: false,
          lang: this.translateService.getDefaultLang()
        };
        ReactDOM.render(
          React.createElement(ExcelReactComponent, options),
          document.getElementById('react-excel-id')
        );
[...]
// Then I load the component with:
<Workbook data={props.data} config={props} />

With this way, I can see the following error on my console:
image

Expected behavior
Is there an issue with my code? It is possible to block the edition?

Screenshots
image

Additional context
I'm using Angular 13 with the react plugin loaded with a wrapper (just for you to know)

Sheet right and left arrows

Describe the bug
Nothing happens when I click on these two bottom sheet name arraws
image

To Reproduce

  1. Open an Excel file with multiple sheets
  2. click on the double left arrows

Expected behavior
Maybe they are supposed to move the view from one sheet to the next (or the previous)

Screenshots
image

Additional context
I'm using Angular 13 with the react plugin loaded with a wrapper (just for you to know)

CSS needs to be imported manually

Describe the bug
CSS needs to be imported manually

To Reproduce
Try this code:

import { Workbook } from "@fortune-sheet/react";
// try commenting the next line out
// import "@fortune-sheet/react/dist/index.css";

const App = () => {
  const x = 1;
  return (
    <div
      style={{
        width: "100%",
        height: "500px"
      }}
    >
      <Workbook
        data={[
          {
            name: "Empty",
            status: 1,
            celldata: [{ r: 0, c: 0, v: null }]
          }
        ]}
      />
    </div>
  );
};

export default App;

Expected behavior
Auto import or updated the docs(in readme)

Screenshots

Without CSS importing UI remains broken

Additional context
Codesandbox: https://codesandbox.io/s/playground-fortune-sheet-osbs0h?file=/src/App.tsx:0-478

When Formula edition, sheet changing breaks the entire component

Describe the bug
If the allowEdit is true
If the user starts editing a formula, if he changes the sheet (if the user clicks on sheet 2 per example) it will break the entire component.

To Reproduce
Steps to reproduce the behavior:

  1. render the Workbook with allowEdit={true}
  2. start to edit a cell with the formula (like =B1+B2)
  3. validate the edition and add a new Sheet
  4. back to the first sheet
  5. edit the formula cell
  6. click on sheet 2

Expected behavior
The formula edition should be canceled and the new sheet should be displayed

Screenshots
image
image
image

Additional context
I'm using Angular 13 with the react plugin loaded with a wrapper (just for you to know)

Spanish format dropdown list missing element

Describe the bug
There are two empty items in the format dropdown

To Reproduce
image

In the DOM I can see:
image

Expected behavior
We should have values or nothing, but no empty line

Additional context
It happens only with ES language.
If I switch in English it is working fine:
image

Scrollbar out of the box

Describe the bug
The horizontal scrollbar is out of the container.
The scroll bar width exceeds the width of the container

To Reproduce
Default behavior

Expected behavior
The scrollbar width stays inside the container

Screenshots
image
I can change my application setting to use a discreet scrollbar design, even in this mode we can see the width is too big:
image

Additional context
I'm using Angular 13 with the react plugin loaded with a wrapper (just for you to know)

Add Button on sheet bottom should be hiden when readonly mode

Describe the bug
When the config allowEdit is false, the ADD button at the bottom of the sheet should not be visible

To Reproduce
Set config allowEdit to false
Scroll to the bottom of the sheet, you can see the button and the field to set the number of added row
If you click on the button, the row will be added on the rendering

Expected behavior
The button should not be visible at all

Screenshots
image

When readOnly mode, text field formula bar is still editable + the user can swtich the sheet position

Describe the bug
When the config allowEdit is false, the text field in the formula bar should not be editable
AND
The user can still move the sheet name from the right or left position

To Reproduce

  1. Set config allowEdit to false
  2. Select a cell
  3. click on the formula bar and edit the content (the cell value is not updated, but the formula bar value should be editable)
  4. Open an Excel file with more than 1 sheet (2 or 3)
  5. You can still move (drag and drop) one sheet before or after another

Expected behavior
The text field should not be editable (read-only) and the sheet order should not be changed

Screenshots
image
image

Workbook sheets does not re-render when I update the data prop.

Describe the bug
Workbook sheets does not re-render when I change the data prop within a button click event.

To Reproduce
Steps to reproduce the behavior:

  1. Go to fortune-sheet-react-sample repo and clone it.
  2. yarn install
  3. yarn start
  4. When I click the "Set New Sheets" button then I create the new state with newData object and pass it to Workbook's data prop. But Workbook components does not re-render with new sheet and cells.

Expected behavior
I expect the Workbook component to re-render with new sheet.

怎么跑线上的协同demo

我打算执行协同的前端,在命令行执行 yarn storybook。报下面的报错
image

请问怎么运行协同前端的代码

请问如何二次使用data参数重新初始化?

Is your feature request related to a problem? Please describe.
目前表格的初始化为获取到远端data配置后完成第一次加载,但如果使用useState存储data的时候,当data更新后表格不会重新渲染到新的data配置,不知道是否有其他方法可以手动/自动触发这个加载?

Describe the solution you'd like
当data存储在useSatate时,若更新data则表格重新渲染到新的data

Formulas that reference another sheet dosnt work

The formulas that reference another sheet dosnt work

Can be reproduced in online demos of fortuneSheets

I expected it to work like lucky sheet but it is possible that this functionality has not been implemented in fortune sheet yet?

Multiple Instance Issue Solution

Hello,

I have a question that how did you solve the multiple instance problem. 😄
I'm trying to solve this problem in my local luckySheet project.

Regards.

Circular reference

Describe the bug
Error: Circular dependency: node_modules/@formulajs/formulajs/lib/math-trig.js -> node_modules/@formulajs/formulajs/lib/statistical.js -> node_modules/@formulajs/formulajs/lib/math-trig.js

Is there any plan to make a Vue version?

Is your feature request related to a problem? Please describe.
Is there any plan to make a Vue version?

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

CSS

Describe the bug
On my application I was forced to add this custom CSS:

:host{
  ::ng-deep {
    .fortune-fx-input,
    .fortune-name-box-container,
    .fortune-toolbar-item,
    .luckysheet-cell-input {
      color:black
    }
    .fortune-fx-editor {
      background-color: white;
    }
    .fortune-left-top {
      background-color: rgba(194, 194, 194, 0.4);
    }
    .fortune-fx-input{
      text-align: left;
    }
  }
}

Even after adding the dist CSS:
"node_modules/@fortune-sheet/react/dist/index.css"

Expected behavior
Did I make something wrong?
If not, it is possible to add this style directly on the default stylesheet?

Screenshots
image
image

Wrong words wrapping

Describe the bug
Wrapping of words is clipped.

To Reproduce
Input some words especially chinese words, and set the cell wrapping, tune the length of words, will see the wrap cell clips one or two words.

Expected behavior
Correct wrapping calculation.

Screenshots
image

单元格选择框在特定情况下错位

Describe the bug
在表格的最后几行进行编辑,然后按回车,重复上面的操作,直到选中的单元格超出可视区域,并继续重复操作,发现单元格选择框错位。

Expected behavior
单元格选择框正常

Screenshots
image

onChange cell getting issue.

const onChange = useCallback((d: Sheet[]) => {
d[0]["data"][1][1]={"ct": {"fa": "General","t": "g"},"m": "Nameofthescript","v": "Name of the script","bg": "#858a7e","ht": "0",};
console.info(d[0]["data"]);
}, []);

return ;

Please can suggest the example for onChange event for each cell. I couldn't find on it.
above one is failing while I set the cell value.

Suggestion: auditing mechanism for changes

Hi,

It would be nice to consider including an auditing mechanism for changes (actions and data) that are performed in a spreadsheet.

I have seen an interesting idea in the Ethercalc project [https://github.com/audreyt/ethercalc]

Each change is transformed into instructions, for example:

set A1 text t Hi, Friends.
set A2 value n 15
set A3 value n 20
set A4 formula sum(A2:A3)
set A4 font normal bold * *
cut A2:A4 formulas
paste B2 formulas

Others applications, you can persist this and replay changes. It would be a very interesting function with many possibilities, don't you think?

Subsequent property declarations must have the same type.

Describe the bug
Error: node_modules/resize-observer-polyfill/src/index.d.ts:19:18 - error TS2717: Subsequent property declarations must have the same type. Property 'contentRect' must be of type 'DOMRectReadOnly', but here has type 'DOMRectReadOnly'.

19 readonly contentRect: DOMRectReadOnly;

To Reproduce
Steps to reproduce the behavior:

  1. use angular13
  2. with typescript 4.6.4
  3. npm start
  4. See error

Expected behavior
The issue is because of the latest version of TypeScript ships with an official type definition, which this library conflicts with.

Assignment regarding Excel export

Is your feature request related to a problem? Please describe.
Export excel

Describe the solution you'd like
To have a download button, which will directly download as Excel

Describe alternatives you've considered
use something like exceljs

Additional context
Included in roadmap

If no one else is working on it, can I get assigned to it?

yarn build时出现TypeError: fs.rmSync is not a function错误

fortune-sheet 版本 0.6.3
yarn build时出现TypeError: fs.rmSync is not a function错误

`@fortune-sheet/react: Build umd success entry: src/index.ts
@fortune-sheet/react: Build cjs with rollup
end value has mixed support, consider using flex-end instead
@fortune-sheet/react: Build cjs success entry: src/index.ts
@fortune-sheet/react: Build esm with rollup
end value has mixed support, consider using flex-end instead
@fortune-sheet/react: Build esm success entry: src/index.ts
/fortunesheet/scripts/build.js:22
fs.rmSync("packages/core/tsconfig.json");
^

TypeError: fs.rmSync is not a function
at Object. (/fortunesheet/scripts/build.js:22:4)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`

yarn的版本为:1.22.19

Issue with line breaking

Describe the bug
When there is multiple rows in a cell, then delete the last row, then the words aligment is wrong, especially under "horizontal center" style.

To Reproduce
Steps to reproduce the behavior:

  1. Input multipe rows in the same cell with "alt+enter".
  2. Delete the last row, and the count of ramining rows is more than one.
  3. See the style error.

Screenshots
image

Canva dimension auto resize

Is your feature request related to a problem? Please describe.
When I resize the container where the sheet is displayed, the canvas dimension does not update and the rendering does not match the new size.
image

Describe the solution you'd like
Having a resize observer to adapt the canvas width and height every time the values are updated

Describe alternatives you've considered
I will try to develop this observer on my own side (in my own application) to fix the size by myself - but it could be better to have this fix included in the lib

Additional context
I'm using Angular 13 with the react plugin loaded with a wrapper (just for you to know)

No non-react examples

Not everyone uses react, can you provide samples, a hello world if you will, of fortune sheet/core? using just vanilla js?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.