MCPcopy Index your code
hub / github.com/MathNya/umya-spreadsheet

github.com/MathNya/umya-spreadsheet @3.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.0.0 ↗ · + Follow
8,226 symbols 16,734 edges 585 files 55 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

umya-spreadsheet

Result Image

Crates.io Github CI Crates.io GitHub Sponsor

Description

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.

Chatting

The chat will be closed.

(Maybe I didn't set it up right, but it's because I no longer get notifications when new messages come in and I don't notice them anymore.)

Please mention in issues if you have any questions.

Version 3.0.0 has been released

This update contains breaking changes. Please refer to this page when upgrading from version 2.x to 3.x. https://github.com/MathNya/umya-spreadsheet/blob/master/CHANGELOG.md

Usage

Installation

Add the following code to Cargo.toml

[dependencies]
umya-spreadsheet = "3.0.0"

# WebAssembly support
umya-spreadsheet = { version = "3.0.0", features = ["js"] }

# Use only png for image processing
umya-spreadsheet = { version = "3.0.0", features = ["image/png"] }

Add the following code to main.rs

extern crate umya_spreadsheet;

Read file

let path = std::path::Path::new("./tests/test_files/aaa.xlsx");
let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap();

Read file (Lazy)

Delays the loading of the worksheet until it is needed.
When loading a file with a large amount of data, response improvement can be expected.

let path = std::path::Path::new("./tests/test_files/aaa.xlsx");
let mut book = umya_spreadsheet::reader::xlsx::lazy_read(path).unwrap();

New file

let mut book = umya_spreadsheet::new_file();

Write file

let path = std::path::Path::new("./tests/result_files/bbb.xlsx");
let _unused =  umya_spreadsheet::writer::xlsx::write(&book, path);

Write file with password

let path = std::path::Path::new("./tests/result_files/bbb.xlsx");
let _unused =  umya_spreadsheet::writer::xlsx::write_with_password(&book, path, "password");
let from_path = std::path::Path::new("./tests/test_files/aaa.xlsx");
let to_path = std::path::Path::new("./tests/result_files/bbb.xlsx");
let _unused =  umya_spreadsheet::writer::xlsx::set_password(&from_path, &to_path, "password");

Read Value

let mut book = umya_spreadsheet::new_file();
book.sheet_by_name("Sheet1").unwrap().cell("A1").value();
book.sheet_by_name("Sheet1").unwrap().cell((1, 1)).value();
book.sheet_by_name("Sheet1").unwrap().cell((1, 1)).value();
book.sheet_mut(&0).unwrap().cell((1, 1)).value();

Change Value

let mut book = umya_spreadsheet::new_file();
book.sheet_by_name_mut("Sheet1").unwrap().cell_mut("A1").set_value("TEST1");
book.sheet_mut(&0).unwrap().cell_mut("A1").set_value("TEST2");

Move Values

let range = "A1:A3";
let row = 10;
let column = 2;
book.sheet_by_name_mut("Sheet1").unwrap().move_range(range, &row, &column);

Change Style

let mut book = umya_spreadsheet::new_file();
let mut style = book.sheet_by_name_mut("Sheet1").unwrap().style_mut("A1");
// fill color on red.
style.set_background_color(umya_spreadsheet::Color::COLOR_RED);

New Chart

let mut book = umya_spreadsheet::new_file();
// Add Chart
let mut from_marker = umya_spreadsheet::structs::drawing::spreadsheet::MarkerType::default();
from_marker.set_coordinate("C1");
let mut to_marker = umya_spreadsheet::structs::drawing::spreadsheet::MarkerType::default();
to_marker.set_coordinate("D11");
let area_chart_series_list = vec![
    "Sheet1!$A$1:$A$10",
    "Sheet1!$B$1:$B$10",
];
let mut chart = umya_spreadsheet::structs::Chart::default();
chart.new_chart(
    umya_spreadsheet::structs::ChartType::LineChart,
    from_marker,
    to_marker,
    area_chart_series_list,
);
book.sheet_by_name_mut("Sheet1").unwrap()
    .add_chart(chart);

Struct

Pass the book as a Workbook to modify it in other functions.


let mut book = umya_spreadsheet::new_file();
let _unused =  book.new_sheet("Sheet2");
update_excel(&mut book);

fn update_excel(book:  &mut Workbook) {
   book.sheet_by_name_mut("Sheet2").unwrap().cell_mut("A1").set_value("Test"); 
}

See the next chapter for implementation status and more detailed usage.

Support Status

Function detail example
file reader xlsx, xlsm here.
file lazy_reader xlsx, xlsm here.
file writer xlsx, xlsm here.
csv here.
file writer with password xlsx, xlsm here.
worksheet read, new, copy here.
cell value read, edit, formated value. here.
cell style read, edit here.
columns read, edit, auto width here.
rows read, edit
charts read, edit here.
drawings read, edit(Still might be inconvenient.)
images read, edit here.
ole objects read, edit(Still might be inconvenient.)

License

MIT

Contributing

Contributions by way of pull requests are welcome! Please make sure your code uses:

  • cargo fmt for formatting
  • clippy
cargo +nightly fmt --all
cargo clippy -- -D warnings

Acknowledgements

These are the people who have supported the umya-spreadsheet project. We would like to express our heartfelt gratitude to them.

8191, agentjill, attila-lin, boseongkim32, c-git, cstkingkey, DaimoniX, developer0hye, fabianboesiger, ggodlewski, gitter-badger, hackers267, iancormac84, jimchan3301, jmbrunskill, john-dc252, kazuk, kjh618, KyGost, lanej, matt-duch, mxsrm, nikvoid, oxabz, patrickomatic, piaoger, popen2, PSU3D0, RoloEdits, SamuelMarks, schungx, sjfhsjfh, tomgroenwoldt, tzfun, ubamrein, usagi, vonkruel, WilliamTCarroll, wolfiesch, xamgore, yerlibilgin, zjhsd2007

Projects using umya-spreadsheet

Community projects built with umya-spreadsheet (not endorsements). - spreadsheet-mcp - MCP server for spreadsheet analysis/editing (xlsx/xlsm via umya-spreadsheet) - formualizer - Arrow-backed spreadsheet engine and formula parser with excel parity (xlsx/xlsm via umya-spreadsheet)

Extension points exported contracts — how you extend this code

AdjustmentCoordinateWithSheet (Interface)
(no doc) [14 implementers]
src/traits/adjustment_coordinate_with_sheet.rs
EnumTrait (Interface)
(no doc) [64 implementers]
src/structs/enum_trait.rs
AnalysisMethod (Interface)
(no doc) [1 implementers]
src/helper/html.rs
AdjustmentCoordinate (Interface)
(no doc) [19 implementers]
src/traits/adjustment_coordinate.rs
BorderPropertiesType (Interface)
(no doc)
src/structs/border_properties_type.rs
AdjustmentValue (Interface)
(no doc) [8 implementers]
src/traits/adjustment_value.rs
AdjustmentCoordinateWith2Sheet (Interface)
(no doc) [4 implementers]
src/traits/adjustment_coordinate_with_2sheet.rs

Core symbols most depended-on inside this repo

write_start_tag
called by 559
src/writer/driver.rs
set_value
called by 353
src/structs/text.rs
has_value
called by 331
src/structs/color.rs
write_end_tag
called by 326
src/writer/driver.rs
set_val
called by 287
src/structs/bold.rs
value
called by 249
src/structs/text.rs
value_str
called by 208
src/structs/string_value.rs
value
called by 194
src/structs/drawing/charts/series_text.rs

Shape

Method 7,357
Class 423
Function 365
Enum 74
Interface 7

Languages

Rust100%

Modules by API surface

src/structs/worksheet.rs317 symbols
tests/integration_test.rs121 symbols
src/structs/drawing/charts/plot_area.rs110 symbols
src/structs/workbook.rs106 symbols
src/structs/pivot_table_definition.rs99 symbols
src/structs/font.rs92 symbols
src/structs/drawing/charts/date_axis.rs88 symbols
src/structs/drawing/charts/category_axis.rs88 symbols
src/structs/drawing/charts/area_chart_series.rs80 symbols
src/structs/drawing/charts/value_axis.rs78 symbols
src/structs/drawing/run_properties.rs76 symbols
src/structs/cell.rs76 symbols

For agents

$ claude mcp add umya-spreadsheet \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact