Skip to main content

Reflex wrapper for FortuneSheet with Excel import/export (FortuneExcel)

Project description

reflex-fortune-sheet

Reflex wrapper for FortuneSheet with Excel import/export via FortuneExcel.

Reflex 封装的 FortuneSheet 表格组件,并通过 FortuneExcel 支持 Excel 导入/导出。

English · 中文 · Framework docs (EN)


English

Features

  • Spreadsheet UI powered by @fortune-sheet/react
  • Excel/CSV import & export toolbar (FortuneExcel), with localized tooltips
  • on_change — full workbook snapshot (save / persist)
  • on_op — fine-grained Op stream (audit / collaboration hooks)
  • revision — explicit reload control (avoids controlled-data loops)
  • Built-in StrictMode on_op dedupe (safe default for library consumers)

Requirements

  • Python >=3.13
  • Reflex >=0.9.0

Install

# From this repo (editable)
pip install -e .

# Or add as a path / git dependency in your project

Frontend packages (@fortune-sheet/react, @corbe30/fortune-excel) are declared as Reflex lib_dependencies and install automatically when the app compiles.

Quick start

import reflex as rx
from reflex_fortune_sheet import fortune_sheet


class State(rx.State):
    sheets: list[dict] = [
        {
            "name": "Sheet1",
            "row": 36,
            "column": 18,
            "celldata": [
                {"r": 0, "c": 0, "v": {"v": "Hello", "m": "Hello"}},
            ],
        }
    ]
    revision: int = 0

    @rx.event
    def on_change(self, data: list[dict]):
        # Snapshot only — do NOT bump revision here.
        self.sheets = data

    @rx.event
    def on_op(self, ops: list[dict]):
        # Fine-grained ops for audit / sync.
        print(ops)

    @rx.event
    def reload(self):
        # Force Workbook remount with current `sheets`.
        self.revision += 1


def index():
    return fortune_sheet(
        data=State.sheets,
        revision=State.revision,
        lang="en",
        height="70vh",
        width="100%",
        on_change=State.on_change,
        on_op=State.on_op,
    )


app = rx.App()
app.add_page(index)

Run the demo in this repo

reflex run

App module: reflex_fortune_sheet_demo.

Data contract (important)

Prop / event Role
data Initial / revision-scoped input only
revision Bump to force-reload Workbook from data
on_change Content snapshot (selection ignored)
on_op Op[] from FortuneSheet (onOp)

Changing data without bumping revision does not remount the sheet. That prevents feedback loops when you persist on_change back into state.

Documentation

Full English framework docs:

Upstream:

License

See repository license file if present; otherwise treat as project-local until published.


中文

功能

  • 基于 @fortune-sheet/react 的在线表格
  • 通过 FortuneExcel 提供 Excel/CSV 导入导出工具栏(工具提示可随 lang 本地化)
  • on_change:整表快照(适合保存/持久化)
  • on_op:细粒度 Op 流(适合审计/协同同步)
  • revision:显式控制重载(避免受控数据回环)
  • 默认开启 StrictMode 下的 on_op 去重(面向库用户的安全默认)

环境要求

  • Python >=3.13
  • Reflex >=0.9.6

安装

# 本仓库可编辑安装
pip install -e .

# 或在你的项目中以 path / git 依赖引入

前端依赖(@fortune-sheet/react@corbe30/fortune-excel)已在组件的 lib_dependencies 中声明,应用编译时会自动安装。

快速开始

import reflex as rx
from reflex_fortune_sheet import fortune_sheet


class State(rx.State):
    sheets: list[dict] = [
        {
            "name": "Sheet1",
            "row": 36,
            "column": 18,
            "celldata": [
                {"r": 0, "c": 0, "v": {"v": "你好", "m": "你好"}},
            ],
        }
    ]
    revision: int = 0

    @rx.event
    def on_change(self, data: list[dict]):
        # 只存快照 —— 这里不要 bump revision。
        self.sheets = data

    @rx.event
    def on_op(self, ops: list[dict]):
        print(ops)

    @rx.event
    def reload(self):
        self.revision += 1


def index():
    return fortune_sheet(
        data=State.sheets,
        revision=State.revision,
        lang="zh",
        height="70vh",
        width="100%",
        on_change=State.on_change,
        on_op=State.on_op,
    )


app = rx.App()
app.add_page(index)

运行本仓库 Demo

reflex run

应用名:reflex_fortune_sheet_demo

数据契约(重要)

属性 / 事件 作用
data 仅作为初始 / revision 作用域输入
revision 递增后强制用当前 data 重载 Workbook
on_change 内容快照(忽略选区等 UI 状态)
on_op FortuneSheet onOp 产出的 Op[]

只改 data增加 revision不会重挂载表格。这样你把 on_change 写回 State 时不会形成受控回环。

文档

英文框架文档:

上游文档:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_fortune_sheet-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reflex_fortune_sheet-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file reflex_fortune_sheet-0.1.0.tar.gz.

File metadata

  • Download URL: reflex_fortune_sheet-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reflex_fortune_sheet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c98567ec2a3a71fc421d3db9e554a31dbf772580cfe2d0ff071ad70128f00da
MD5 6a9a955a9ba97de1e35b2296f7810139
BLAKE2b-256 2ee9ae131a181d83ae2211791a9194ff1028d1bf90afdb0a3d0227c9877d4fce

See more details on using hashes here.

File details

Details for the file reflex_fortune_sheet-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for reflex_fortune_sheet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14448f4654e2272556abf60c6951e079a8c7f36f2103a68bf90a08964214b3f2
MD5 3e58bc34e8fb9a8e282f525fefb3c1a1
BLAKE2b-256 95bb624dc7cc9368866adfac70ecfdc06e4cb7c8517917200296efea1d041af5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page