Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ Programmed in Rust, you will be able to use it from a variety of programming lan

We will build different _skins_: in the terminal, as a desktop application or use it in you own web application.

## Haiku Interlude

Rust winds compile dreams
Cells whisper through iron grids
Sheets bloom into night

Code flows like clear streams
Formulas find gentle homes
Numbers learn to sing

Data sparks like dawn
Pivot tales weave patient threads
Insights stretch their wings

Engines hum soft tunes
Concurrency keeps the beat
Models wake with light

# Building

```bash
Expand Down
6 changes: 5 additions & 1 deletion xlsx/examples/hello_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
model.evaluate();

// saves to disk
save_to_xlsx(&model, "hello-calc.xlsx")?;
let output_path = "hello-calc.xlsx";
if std::path::Path::new(output_path).exists() {
std::fs::remove_file(output_path)?;
}
save_to_xlsx(&model, output_path)?;
Ok(())
}
6 changes: 5 additions & 1 deletion xlsx/examples/hello_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
model.set_cell_style(sheet, row, column, &style)?;

// saves to disk
save_to_xlsx(&model, "hello-styles.xlsx")?;
let output_path = "hello-styles.xlsx";
if std::path::Path::new(output_path).exists() {
std::fs::remove_file(output_path)?;
}
save_to_xlsx(&model, output_path)?;
Ok(())
}
6 changes: 5 additions & 1 deletion xlsx/examples/widths_and_heights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
worksheet.set_row_height(row, row_height)?;

// saves to disk
save_to_xlsx(&model, "widths-and-heights.xlsx")?;
let output_path = "widths-and-heights.xlsx";
if std::path::Path::new(output_path).exists() {
std::fs::remove_file(output_path)?;
}
save_to_xlsx(&model, output_path)?;
Ok(())
}
46 changes: 39 additions & 7 deletions xlsx/src/import/worksheets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,36 @@ enum ParseReferenceError {
// NB: Maybe use regexes for this?
fn parse_reference(s: &str) -> Result<CellReferenceRC, ParseReferenceError> {
let bytes = s.as_bytes();
let mut sheet_name = "".to_string();
let mut column = "".to_string();
let mut row = "".to_string();
let mut sheet_name = String::new();
let mut column = String::new();
let mut row = String::new();
let mut state = "sheet"; // "sheet", "col", "row"
for &byte in bytes {
match state {
"sheet" => {
if byte == b'!' {
state = "col"
state = "col";
} else {
sheet_name.push(byte as char);
}
}
"col" => {
if byte == b'$' {
continue;
}
if byte.is_ascii_alphabetic() {
column.push(byte as char);
column.push((byte as char).to_ascii_uppercase());
} else {
state = "row";
row.push(byte as char);
if byte != b'$' {
row.push(byte as char);
}
}
}
_ => {
row.push(byte as char);
if byte != b'$' {
row.push(byte as char);
}
}
}
}
Expand All @@ -300,6 +307,31 @@ fn parse_reference(s: &str) -> Result<CellReferenceRC, ParseReferenceError> {
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn parse_reference_supports_absolute_references() {
let reference = parse_reference("Sheet 1!$B$12").unwrap();
assert_eq!(reference.sheet, "Sheet 1");
assert_eq!(reference.column, 2);
assert_eq!(reference.row, 12);
}

#[test]
fn parse_reference_supports_mixed_absolute_relative() {
let reference = parse_reference("Data!$C4").unwrap();
assert_eq!(reference.sheet, "Data");
assert_eq!(reference.column, 3);
assert_eq!(reference.row, 4);
let reference = parse_reference("Pivot!D$7").unwrap();
assert_eq!(reference.sheet, "Pivot");
assert_eq!(reference.column, 4);
assert_eq!(reference.row, 7);
}
}

fn from_a1_to_rc(
formula: String,
worksheets: &[String],
Expand Down
Loading