#spreadsheet #xlsx #reader-writer #excel #read-file #file-reader #write-file

umya-spreadsheet

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

72 releases (15 stable)

Uses old Rust 2015

2.0.0 Jul 9, 2024
1.3.0 Jul 6, 2024
1.2.7 May 28, 2024
1.2.3 Mar 1, 2024
0.1.17-beta Oct 27, 2020

#120 in Parser implementations

Download history 378/week @ 2024-04-04 285/week @ 2024-04-11 585/week @ 2024-04-18 447/week @ 2024-04-25 362/week @ 2024-05-02 275/week @ 2024-05-09 276/week @ 2024-05-16 498/week @ 2024-05-23 301/week @ 2024-05-30 244/week @ 2024-06-06 305/week @ 2024-06-13 264/week @ 2024-06-20 226/week @ 2024-06-27 659/week @ 2024-07-04 306/week @ 2024-07-11 158/week @ 2024-07-18

1,417 downloads per month
Used in 10 crates (9 directly)

MIT license

9MB
51K SLoC

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.

Update details

ver 2.0.0

  • Revised version 1.3.0 to version 2.0.0.
  • [Breaking changes] The multiple error structures are now combined in structs/error.rs.
  • [Breaking changes] Flexible error settings in cell_value.rs.
  • [Breaking changes] For details on other modifications, please click here.
  • Formula positions are now recalculated when columns or rows are added or deleted.
  • Stronger Error Types implementation. (Thank you, agentjill.)
  • Fixed problems with reading and writing sheets containing images.
  • Other minor bug fix.

Usage

Installation

Add the following code to Cargo.toml

[dependencies]
umya-spreadsheet = "1.3.0"

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

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 _ = umya_spreadsheet::writer::xlsx::write(&book, path);

Write file with password

let path = std::path::Path::new("./tests/result_files/bbb.xlsx");
let _ = 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 _ = umya_spreadsheet::writer::xlsx::set_password(&from_path, &to_path, "password");

Read Value

let mut book = umya_spreadsheet::new_file();
book.get_sheet_by_name("Sheet1").unwrap().get_cell("A1").get_value();
book.get_sheet_by_name("Sheet1").unwrap().get_cell((1, 1)).get_value();
book.get_sheet_by_name("Sheet1").unwrap().get_cell((&1, &1)).get_value();
book.get_sheet_mut(0).unwrap().get_cell((&1, &1)).get_value();

Change Value

let mut book = umya_spreadsheet::new_file();
book.get_sheet_by_name_mut("Sheet1").unwrap().get_cell_mut("A1").set_value("TEST1");
book.get_sheet_mut(0).unwrap().get_cell_mut("A1").set_value("TEST2");

Move Values

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

Change Style

let mut book = umya_spreadsheet::new_file();
let mut style = book.get_sheet_by_name_mut("Sheet1").unwrap().get_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.get_sheet_by_name_mut("Sheet1").unwrap()
    .add_chart(chart);

Struct

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


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

fn update_excel(book: &mut Spreadsheet) {
   book.get_sheet_by_name_mut("Sheet2").unwrap().get_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

Dependencies

~17–25MB
~424K SLoC