Skip to main content

Crate autumn_plugin_univer

Crate autumn_plugin_univer 

Source
Expand description

Univer spreadsheets for Autumn, with Maud + htmx ergonomics.

Add UniverPlugin to the app. Put univer_stylesheet() and univer_script() in the page <head>. Render a Spreadsheet:

use autumn_plugin_univer::{
    Cell, Sheet, Spreadsheet, UniverPlugin, Workbook, univer_script, univer_stylesheet,
};
use autumn_web::prelude::*;

#[get("/")]
async fn index() -> Markup {
    let workbook = Workbook::builder("budget", "Budget")
        .sheet(
            Sheet::new("q1", "Q1")
                .with_row(0, [Cell::text("Rent"), Cell::number(1200.0)])
                .with_cell(1, 1, Cell::formula("=B1*12")),
        )
        .build()
        .unwrap_or_else(|_| Workbook::empty("budget"));
    html! {
        html {
            head { (univer_stylesheet()) (univer_script()) }
            body {
                (Spreadsheet::new("budget").workbook(&workbook).save_url("/budget"))
            }
        }
    }
}

autumn_web::app()
    .plugin(UniverPlugin::new())
    .routes(routes![index])
    .run()
    .await;

The plugin vendors Univer 1.0 (Apache-2.0) as one code-split ES module bundle. No npm, no bundler and no CDN in the host app. The bundle is the UNIVER_ASSETS Autumn plugin asset bundle. It serves from memory under /static/_plugins/univer/ with content-hashed, immutable URLs and SRI hashes.

Read a saved sheet back with the WorkbookSnapshot extractor. It validates the data against the Workbook invariants and Limits.

§Limits

  • Only the open-source sheets core preset is in. Univer Pro features (XLSX import and export, collaboration, charts) are not.
  • Each plugin release pins one Univer version (see UNIVER_VERSION).
  • Without JavaScript, the page shows a <noscript> notice.

Structs§

Cell
One cell (Univer ICellData).
CellRef
A cell position. Both parts start at zero: A1 is (0, 0).
Limits
Size limits for Workbook::validate_with.
Sheet
One sheet (Univer IWorksheetData).
SheetId
The id of a Sheet in a workbook.
Spreadsheet
The mount markup for one Univer workbook.
UniverPlugin
Installs the Univer assets in an Autumn app.
UnknownLocale
The error for a locale code that is not in this build.
Workbook
A workbook (Univer IWorkbookData).
WorkbookBuilder
Builds a valid Workbook. See Workbook::builder.
WorkbookId
The id of a Workbook.
WorkbookSnapshot
A request body that holds a valid Workbook.

Enums§

CellType
The cell type hint (Univer t, CellValueType).
CellValue
A cell value (Univer v).
Locale
The UI language of a Spreadsheet.
WorkbookError
Why a workbook is not valid. See the module docs for the invariants.

Constants§

ASSETS_NAMESPACE
URL namespace of the bundle. Files serve under /static/_plugins/univer/.
PLUGIN_NAME
The plugin name in Autumn diagnostics.
UNIVER_VERSION
The Univer version in assets/dist/.

Statics§

UNIVER_ASSETS
The plugin asset bundle.

Functions§

save_button
Renders a button that saves the spreadsheet with this DOM id.
univer_script
Renders the <script> tags that load Univer and the mount script.
univer_stylesheet
Renders the <link> tags for the Univer and plugin stylesheets.