mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-24 05:50:02 -04:00
feat: load and save xlsx files
This commit is contained in:
parent
dce9b1fca0
commit
a27d2871c2
@ -1,7 +1,12 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use ironcalc::base::{
|
use ironcalc::{
|
||||||
types::{SheetData, Worksheet},
|
base::{
|
||||||
Model,
|
locale, types::{SheetData, Worksheet}, Model
|
||||||
|
},
|
||||||
|
export::save_to_xlsx,
|
||||||
|
import::load_from_xlsx,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A spreadsheet book with some internal state tracking.
|
/// A spreadsheet book with some internal state tracking.
|
||||||
@ -12,6 +17,28 @@ pub struct Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Book {
|
impl Book {
|
||||||
|
|
||||||
|
/// Construct a new book from a Model
|
||||||
|
pub fn new(model: Model) -> Self {
|
||||||
|
Self {
|
||||||
|
model,
|
||||||
|
current_sheet: 0,
|
||||||
|
current_location: (0, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(zaphar): Should I support ICalc?
|
||||||
|
/// Construct a new book from a path.
|
||||||
|
pub fn new_from_xlsx(path: &str, locale: &str, tz: &str) -> Result<Self> {
|
||||||
|
Ok(Self::new(load_from_xlsx(path, locale, tz)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save book to an xlsx file.
|
||||||
|
pub fn save_to_xlsx(&self, path: &str) -> Result<()> {
|
||||||
|
save_to_xlsx(&self.model, path)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the currently set sheets name.
|
/// Get the currently set sheets name.
|
||||||
pub fn get_sheet_name(&self) -> Result<&str> {
|
pub fn get_sheet_name(&self) -> Result<&str> {
|
||||||
Ok(&self.get_sheet()?.name)
|
Ok(&self.get_sheet()?.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user