Compare commits
1 Commits
feature-ni
...
varum-chan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7858f7aa9 |
5
.github/workflows/test-coverage.yaml
vendored
5
.github/workflows/test-coverage.yaml
vendored
@@ -1,7 +1,10 @@
|
|||||||
name: Coverage
|
name: Coverage
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
- Fixed several issues with pasting content
|
- Fixed several issues with pasting content
|
||||||
- Fixed several issues with borders
|
- Fixed several issues with borders
|
||||||
- Fixed bug where columns and rows could be resized to negative width and height, respectively
|
|
||||||
|
|
||||||
## [0.2.0] - 2024-11-06 (The HN release)
|
## [0.2.0] - 2024-11-06 (The HN release)
|
||||||
|
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -10,7 +10,6 @@ format:
|
|||||||
|
|
||||||
.PHONY: tests
|
.PHONY: tests
|
||||||
tests: lint
|
tests: lint
|
||||||
cargo test
|
|
||||||
make remove-artifacts
|
make remove-artifacts
|
||||||
# Regretabbly we need to build the wasm twice, once for the nodejs tests
|
# Regretabbly we need to build the wasm twice, once for the nodejs tests
|
||||||
# and a second one for the vitest.
|
# and a second one for the vitest.
|
||||||
|
|||||||
@@ -176,3 +176,18 @@ impl Cell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementing methods for MergedCells struct
|
||||||
|
|
||||||
|
impl MergedCells {
|
||||||
|
pub fn is_cell_part_of_merged_cells(&self, row: i32, col: i32) -> bool {
|
||||||
|
// This is merge Mother cell so do not include this cell as part of Merged Cells
|
||||||
|
if row == self.0 && col == self.1 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result: bool = (row >= self.0 && row <= self.2) && (col >= self.1 && col <= self.3);
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ pub(crate) const DEFAULT_COLUMN_WIDTH: f64 = 125.0;
|
|||||||
pub(crate) const DEFAULT_ROW_HEIGHT: f64 = 28.0;
|
pub(crate) const DEFAULT_ROW_HEIGHT: f64 = 28.0;
|
||||||
pub(crate) const COLUMN_WIDTH_FACTOR: f64 = 12.0;
|
pub(crate) const COLUMN_WIDTH_FACTOR: f64 = 12.0;
|
||||||
pub(crate) const ROW_HEIGHT_FACTOR: f64 = 2.0;
|
pub(crate) const ROW_HEIGHT_FACTOR: f64 = 2.0;
|
||||||
pub(crate) const DEFAULT_WINDOW_HEIGHT: i64 = 600;
|
pub(crate) const DEFAULT_WINDOW_HEIGH: i64 = 600;
|
||||||
pub(crate) const DEFAULT_WINDOW_WIDTH: i64 = 800;
|
pub(crate) const DEFAULT_WINDOW_WIDTH: i64 = 800;
|
||||||
|
|
||||||
pub(crate) const LAST_COLUMN: i32 = 16_384;
|
pub(crate) const LAST_COLUMN: i32 = 16_384;
|
||||||
|
|||||||
@@ -24,25 +24,6 @@ fn test_get_tokens() {
|
|||||||
assert_eq!(l.end, 10);
|
assert_eq!(l.end, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn get_tokens_unicode() {
|
|
||||||
let formula = "'🇵🇭 Philippines'!A1";
|
|
||||||
let t = get_tokens(formula);
|
|
||||||
assert_eq!(t.len(), 1);
|
|
||||||
|
|
||||||
let expected = TokenType::Reference {
|
|
||||||
sheet: Some("🇵🇭 Philippines".to_string()),
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
absolute_column: false,
|
|
||||||
absolute_row: false,
|
|
||||||
};
|
|
||||||
let l = t.first().expect("expected token");
|
|
||||||
assert_eq!(l.token, expected);
|
|
||||||
assert_eq!(l.start, 0);
|
|
||||||
assert_eq!(l.end, 19);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple_tokens() {
|
fn test_simple_tokens() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -49,7 +49,15 @@ pub mod stringify;
|
|||||||
pub mod walk;
|
pub mod walk;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod test;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_ranges;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_move_formula;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_tables;
|
||||||
|
|
||||||
pub(crate) fn parse_range(formula: &str) -> Result<(i32, i32, i32, i32), String> {
|
pub(crate) fn parse_range(formula: &str) -> Result<(i32, i32, i32, i32), String> {
|
||||||
let mut lexer = lexer::Lexer::new(
|
let mut lexer = lexer::Lexer::new(
|
||||||
@@ -514,6 +522,20 @@ impl Parser {
|
|||||||
let mut absolute_row1 = left.absolute_row;
|
let mut absolute_row1 = left.absolute_row;
|
||||||
let mut absolute_row2 = right.absolute_row;
|
let mut absolute_row2 = right.absolute_row;
|
||||||
|
|
||||||
|
if self.lexer.is_a1_mode() {
|
||||||
|
if !left.absolute_row {
|
||||||
|
row1 -= context.row
|
||||||
|
};
|
||||||
|
if !left.absolute_column {
|
||||||
|
column1 -= context.column
|
||||||
|
};
|
||||||
|
if !right.absolute_row {
|
||||||
|
row2 -= context.row
|
||||||
|
};
|
||||||
|
if !right.absolute_column {
|
||||||
|
column2 -= context.column
|
||||||
|
};
|
||||||
|
}
|
||||||
if row1 > row2 {
|
if row1 > row2 {
|
||||||
(row2, row1) = (row1, row2);
|
(row2, row1) = (row1, row2);
|
||||||
(absolute_row2, absolute_row1) = (absolute_row1, absolute_row2);
|
(absolute_row2, absolute_row1) = (absolute_row1, absolute_row2);
|
||||||
@@ -522,22 +544,6 @@ impl Parser {
|
|||||||
(column2, column1) = (column1, column2);
|
(column2, column1) = (column1, column2);
|
||||||
(absolute_column2, absolute_column1) = (absolute_column1, absolute_column2);
|
(absolute_column2, absolute_column1) = (absolute_column1, absolute_column2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.lexer.is_a1_mode() {
|
|
||||||
if !absolute_row1 {
|
|
||||||
row1 -= context.row
|
|
||||||
};
|
|
||||||
if !absolute_column1 {
|
|
||||||
column1 -= context.column
|
|
||||||
};
|
|
||||||
if !absolute_row2 {
|
|
||||||
row2 -= context.row
|
|
||||||
};
|
|
||||||
if !absolute_column2 {
|
|
||||||
column2 -= context.column
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
match sheet_index {
|
match sheet_index {
|
||||||
Some(index) => Node::RangeKind {
|
Some(index) => Node::RangeKind {
|
||||||
sheet_name: sheet,
|
sheet_name: sheet,
|
||||||
|
|||||||
@@ -456,65 +456,11 @@ fn stringify(
|
|||||||
};
|
};
|
||||||
format!("{}{}{}", x, kind, y)
|
format!("{}{}{}", x, kind, y)
|
||||||
}
|
}
|
||||||
OpPowerKind { left, right } => {
|
OpPowerKind { left, right } => format!(
|
||||||
let x = match **left {
|
"{}^{}",
|
||||||
BooleanKind(_)
|
stringify(left, context, displace_data, use_original_name),
|
||||||
| NumberKind(_)
|
stringify(right, context, displace_data, use_original_name)
|
||||||
| StringKind(_)
|
),
|
||||||
| ReferenceKind { .. }
|
|
||||||
| RangeKind { .. }
|
|
||||||
| WrongReferenceKind { .. }
|
|
||||||
| VariableKind(_)
|
|
||||||
| WrongRangeKind { .. } => {
|
|
||||||
stringify(left, context, displace_data, use_original_name)
|
|
||||||
}
|
|
||||||
OpRangeKind { .. }
|
|
||||||
| OpConcatenateKind { .. }
|
|
||||||
| OpProductKind { .. }
|
|
||||||
| OpPowerKind { .. }
|
|
||||||
| FunctionKind { .. }
|
|
||||||
| InvalidFunctionKind { .. }
|
|
||||||
| ArrayKind(_)
|
|
||||||
| UnaryKind { .. }
|
|
||||||
| ErrorKind(_)
|
|
||||||
| ParseErrorKind { .. }
|
|
||||||
| OpSumKind { .. }
|
|
||||||
| CompareKind { .. }
|
|
||||||
| EmptyArgKind => format!(
|
|
||||||
"({})",
|
|
||||||
stringify(left, context, displace_data, use_original_name)
|
|
||||||
),
|
|
||||||
};
|
|
||||||
let y = match **right {
|
|
||||||
BooleanKind(_)
|
|
||||||
| NumberKind(_)
|
|
||||||
| StringKind(_)
|
|
||||||
| ReferenceKind { .. }
|
|
||||||
| RangeKind { .. }
|
|
||||||
| WrongReferenceKind { .. }
|
|
||||||
| VariableKind(_)
|
|
||||||
| WrongRangeKind { .. } => {
|
|
||||||
stringify(right, context, displace_data, use_original_name)
|
|
||||||
}
|
|
||||||
OpRangeKind { .. }
|
|
||||||
| OpConcatenateKind { .. }
|
|
||||||
| OpProductKind { .. }
|
|
||||||
| OpPowerKind { .. }
|
|
||||||
| FunctionKind { .. }
|
|
||||||
| InvalidFunctionKind { .. }
|
|
||||||
| ArrayKind(_)
|
|
||||||
| UnaryKind { .. }
|
|
||||||
| ErrorKind(_)
|
|
||||||
| ParseErrorKind { .. }
|
|
||||||
| OpSumKind { .. }
|
|
||||||
| CompareKind { .. }
|
|
||||||
| EmptyArgKind => format!(
|
|
||||||
"({})",
|
|
||||||
stringify(right, context, displace_data, use_original_name)
|
|
||||||
),
|
|
||||||
};
|
|
||||||
format!("{}^{}", x, y)
|
|
||||||
}
|
|
||||||
InvalidFunctionKind { name, args } => {
|
InvalidFunctionKind { name, args } => {
|
||||||
format_function(name, args, context, displace_data, use_original_name)
|
format_function(name, args, context, displace_data, use_original_name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,17 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::expressions::lexer::LexerMode;
|
use crate::expressions::lexer::LexerMode;
|
||||||
use crate::expressions::parser::stringify::{
|
use crate::expressions::parser::stringify::DisplaceData;
|
||||||
to_rc_format, to_string, to_string_displaced, DisplaceData,
|
|
||||||
|
use super::super::types::CellReferenceRC;
|
||||||
|
use super::Parser;
|
||||||
|
use super::{
|
||||||
|
super::parser::{
|
||||||
|
stringify::{to_rc_format, to_string},
|
||||||
|
Node,
|
||||||
|
},
|
||||||
|
stringify::to_string_displaced,
|
||||||
};
|
};
|
||||||
use crate::expressions::parser::{Node, Parser};
|
|
||||||
use crate::expressions::types::CellReferenceRC;
|
|
||||||
|
|
||||||
struct Formula<'a> {
|
struct Formula<'a> {
|
||||||
initial: &'a str,
|
initial: &'a str,
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::expressions::parser::move_formula::{move_formula, MoveContext};
|
use crate::expressions::parser::move_formula::{move_formula, MoveContext};
|
||||||
use crate::expressions::parser::Parser;
|
use crate::expressions::types::Area;
|
||||||
use crate::expressions::types::{Area, CellReferenceRC};
|
|
||||||
|
use super::super::types::CellReferenceRC;
|
||||||
|
use super::Parser;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_formula() {
|
fn test_move_formula() {
|
||||||
@@ -2,9 +2,9 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::expressions::lexer::LexerMode;
|
use crate::expressions::lexer::LexerMode;
|
||||||
|
|
||||||
use crate::expressions::parser::stringify::{to_rc_format, to_string};
|
use super::super::parser::stringify::{to_rc_format, to_string};
|
||||||
use crate::expressions::parser::Parser;
|
use super::super::types::CellReferenceRC;
|
||||||
use crate::expressions::types::CellReferenceRC;
|
use super::Parser;
|
||||||
|
|
||||||
struct Formula<'a> {
|
struct Formula<'a> {
|
||||||
formula_a1: &'a str,
|
formula_a1: &'a str,
|
||||||
@@ -6,8 +6,8 @@ use crate::expressions::parser::stringify::to_string;
|
|||||||
use crate::expressions::utils::{number_to_column, parse_reference_a1};
|
use crate::expressions::utils::{number_to_column, parse_reference_a1};
|
||||||
use crate::types::{Table, TableColumn, TableStyleInfo};
|
use crate::types::{Table, TableColumn, TableStyleInfo};
|
||||||
|
|
||||||
use crate::expressions::parser::Parser;
|
use super::super::types::CellReferenceRC;
|
||||||
use crate::expressions::types::CellReferenceRC;
|
use super::Parser;
|
||||||
|
|
||||||
fn create_test_table(
|
fn create_test_table(
|
||||||
table_name: &str,
|
table_name: &str,
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
mod test_general;
|
|
||||||
mod test_issue_155;
|
|
||||||
mod test_move_formula;
|
|
||||||
mod test_ranges;
|
|
||||||
mod test_stringify;
|
|
||||||
mod test_tables;
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#![allow(clippy::panic)]
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::expressions::parser::stringify::to_string;
|
|
||||||
use crate::expressions::parser::Parser;
|
|
||||||
use crate::expressions::types::CellReferenceRC;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn issue_155_parser() {
|
|
||||||
let worksheets = vec!["Sheet1".to_string()];
|
|
||||||
let mut parser = Parser::new(worksheets, HashMap::new());
|
|
||||||
|
|
||||||
// Reference cell is Sheet1!A1
|
|
||||||
let cell_reference = CellReferenceRC {
|
|
||||||
sheet: "Sheet1".to_string(),
|
|
||||||
row: 2,
|
|
||||||
column: 2,
|
|
||||||
};
|
|
||||||
let t = parser.parse("A$1:A2", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "A$1:A2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn issue_155_parser_case_2() {
|
|
||||||
let worksheets = vec!["Sheet1".to_string()];
|
|
||||||
let mut parser = Parser::new(worksheets, HashMap::new());
|
|
||||||
|
|
||||||
// Reference cell is Sheet1!A1
|
|
||||||
let cell_reference = CellReferenceRC {
|
|
||||||
sheet: "Sheet1".to_string(),
|
|
||||||
row: 20,
|
|
||||||
column: 20,
|
|
||||||
};
|
|
||||||
let t = parser.parse("C$1:D2", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "C$1:D2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn issue_155_parser_only_row() {
|
|
||||||
let worksheets = vec!["Sheet1".to_string()];
|
|
||||||
let mut parser = Parser::new(worksheets, HashMap::new());
|
|
||||||
|
|
||||||
// Reference cell is Sheet1!A1
|
|
||||||
let cell_reference = CellReferenceRC {
|
|
||||||
sheet: "Sheet1".to_string(),
|
|
||||||
row: 20,
|
|
||||||
column: 20,
|
|
||||||
};
|
|
||||||
// This is tricky, I am not sure what to do in these cases
|
|
||||||
let t = parser.parse("A$2:B1", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "A1:B$2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn issue_155_parser_only_column() {
|
|
||||||
let worksheets = vec!["Sheet1".to_string()];
|
|
||||||
let mut parser = Parser::new(worksheets, HashMap::new());
|
|
||||||
|
|
||||||
// Reference cell is Sheet1!A1
|
|
||||||
let cell_reference = CellReferenceRC {
|
|
||||||
sheet: "Sheet1".to_string(),
|
|
||||||
row: 20,
|
|
||||||
column: 20,
|
|
||||||
};
|
|
||||||
// This is tricky, I am not sure what to do in these cases
|
|
||||||
let t = parser.parse("D1:$A3", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "$A1:D3");
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#![allow(clippy::panic)]
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::expressions::parser::stringify::to_string;
|
|
||||||
use crate::expressions::parser::Parser;
|
|
||||||
use crate::expressions::types::CellReferenceRC;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn exp_order() {
|
|
||||||
let worksheets = vec!["Sheet1".to_string()];
|
|
||||||
let mut parser = Parser::new(worksheets, HashMap::new());
|
|
||||||
|
|
||||||
// Reference cell is Sheet1!A1
|
|
||||||
let cell_reference = CellReferenceRC {
|
|
||||||
sheet: "Sheet1".to_string(),
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
};
|
|
||||||
let t = parser.parse("(1 + 2)^3 + 4", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "(1+2)^3+4");
|
|
||||||
|
|
||||||
let t = parser.parse("(C5 + 3)^R4", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "(C5+3)^R4");
|
|
||||||
|
|
||||||
let t = parser.parse("(C5 + 3)^(R4*6)", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "(C5+3)^(R4*6)");
|
|
||||||
|
|
||||||
let t = parser.parse("(C5)^(R4)", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "C5^R4");
|
|
||||||
|
|
||||||
let t = parser.parse("(5)^(4)", &Some(cell_reference.clone()));
|
|
||||||
assert_eq!(to_string(&t, &cell_reference), "5^4");
|
|
||||||
}
|
|
||||||
@@ -245,9 +245,6 @@ pub fn format_number(value_original: f64, format: &str, locale: &Locale) -> Form
|
|||||||
}
|
}
|
||||||
ParsePart::Number(p) => {
|
ParsePart::Number(p) => {
|
||||||
let mut text = "".to_string();
|
let mut text = "".to_string();
|
||||||
if let Some(c) = p.currency {
|
|
||||||
text = format!("{}", c);
|
|
||||||
}
|
|
||||||
let tokens = &p.tokens;
|
let tokens = &p.tokens;
|
||||||
value = value * 100.0_f64.powi(p.percent) / (1000.0_f64.powi(p.comma));
|
value = value * 100.0_f64.powi(p.percent) / (1000.0_f64.powi(p.comma));
|
||||||
// p.precision is the number of significant digits _after_ the decimal point
|
// p.precision is the number of significant digits _after_ the decimal point
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ pub struct Lexer {
|
|||||||
pub enum Token {
|
pub enum Token {
|
||||||
Color(i32), // [Red] or [Color 23]
|
Color(i32), // [Red] or [Color 23]
|
||||||
Condition(Compare, f64), // [<=100] (Comparator, number)
|
Condition(Compare, f64), // [<=100] (Comparator, number)
|
||||||
Currency(char), // [$€] ($ currency symbol)
|
|
||||||
Literal(char), // €, $, (, ), /, :, +, -, ^, ', {, }, <, =, !, ~, > and space or scaped \X
|
Literal(char), // €, $, (, ), /, :, +, -, ^, ', {, }, <, =, !, ~, > and space or scaped \X
|
||||||
Spacer(char), // *X
|
Spacer(char), // *X
|
||||||
Ghost(char), // _X
|
Ghost(char), // _X
|
||||||
@@ -275,15 +274,6 @@ impl Lexer {
|
|||||||
self.set_error("Failed to parse condition");
|
self.set_error("Failed to parse condition");
|
||||||
Token::ILLEGAL
|
Token::ILLEGAL
|
||||||
}
|
}
|
||||||
} else if c == '$' {
|
|
||||||
// currency
|
|
||||||
self.read_next_char();
|
|
||||||
if let Some(currency) = self.read_next_char() {
|
|
||||||
self.read_next_char();
|
|
||||||
return Token::Currency(currency);
|
|
||||||
}
|
|
||||||
self.set_error("Failed to parse currency");
|
|
||||||
Token::ILLEGAL
|
|
||||||
} else {
|
} else {
|
||||||
// Color
|
// Color
|
||||||
if let Some(index) = self.consume_color() {
|
if let Some(index) = self.consume_color() {
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ mod test;
|
|||||||
//
|
//
|
||||||
// * Color [Red] or [Color 23] or [Color23]
|
// * Color [Red] or [Color 23] or [Color23]
|
||||||
// * Conditions [<100]
|
// * Conditions [<100]
|
||||||
// * Currency [$€]
|
|
||||||
// * Space _X when X is any given char
|
// * Space _X when X is any given char
|
||||||
// * A spacer of chars: *X where X is repeated as much as possible
|
// * A spacer of chars: *X where X is repeated as much as possible
|
||||||
// * Literals: $, (, ), :, +, - and space
|
// * Literals: $, (, ), :, +, - and space
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ pub struct NumberPart {
|
|||||||
pub is_scientific: bool,
|
pub is_scientific: bool,
|
||||||
pub scientific_minus: bool,
|
pub scientific_minus: bool,
|
||||||
pub exponent_digit_count: i32,
|
pub exponent_digit_count: i32,
|
||||||
pub currency: Option<char>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DatePart {
|
pub struct DatePart {
|
||||||
@@ -115,7 +114,6 @@ impl Parser {
|
|||||||
let mut exponent_digit_count = 0;
|
let mut exponent_digit_count = 0;
|
||||||
let mut number = 'i';
|
let mut number = 'i';
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
let mut currency = None;
|
|
||||||
|
|
||||||
while token != Token::EOF && token != Token::Separator {
|
while token != Token::EOF && token != Token::Separator {
|
||||||
let next_token = self.lexer.next_token();
|
let next_token = self.lexer.next_token();
|
||||||
@@ -172,9 +170,6 @@ impl Parser {
|
|||||||
Token::Condition(cmp, value) => {
|
Token::Condition(cmp, value) => {
|
||||||
condition = Some((cmp, value));
|
condition = Some((cmp, value));
|
||||||
}
|
}
|
||||||
Token::Currency(c) => {
|
|
||||||
currency = Some(c);
|
|
||||||
}
|
|
||||||
Token::QuestionMark => {
|
Token::QuestionMark => {
|
||||||
tokens.push(TextToken::Digit(Digit {
|
tokens.push(TextToken::Digit(Digit {
|
||||||
kind: '?',
|
kind: '?',
|
||||||
@@ -296,7 +291,6 @@ impl Parser {
|
|||||||
is_scientific,
|
is_scientific,
|
||||||
scientific_minus,
|
scientific_minus,
|
||||||
exponent_digit_count,
|
exponent_digit_count,
|
||||||
currency,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,14 +76,6 @@ fn test_color() {
|
|||||||
assert_eq!(format_number(3.1, "[blue]0.00", locale).color, Some(4));
|
assert_eq!(format_number(3.1, "[blue]0.00", locale).color, Some(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dollar_euro() {
|
|
||||||
let locale = get_default_locale();
|
|
||||||
let format = "[$€]#,##0.00";
|
|
||||||
let t = format_number(3.1, format, locale);
|
|
||||||
assert_eq!(t.text, "€3.10");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parts() {
|
fn test_parts() {
|
||||||
let locale = get_default_locale();
|
let locale = get_default_locale();
|
||||||
|
|||||||
@@ -89,9 +89,6 @@ fn compute_future_value(
|
|||||||
if rate == 0.0 {
|
if rate == 0.0 {
|
||||||
return Ok(-pv - pmt * nper);
|
return Ok(-pv - pmt * nper);
|
||||||
}
|
}
|
||||||
if rate == -1.0 && nper < 0.0 {
|
|
||||||
return Err((Error::DIV, "Divide by zero".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let rate_nper = (1.0 + rate).powf(nper);
|
let rate_nper = (1.0 + rate).powf(nper);
|
||||||
let fv = if period_start {
|
let fv = if period_start {
|
||||||
|
|||||||
@@ -136,9 +136,6 @@ impl Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fn_or(&mut self, args: &[Node], cell: CellReferenceIndex) -> CalcResult {
|
pub(crate) fn fn_or(&mut self, args: &[Node], cell: CellReferenceIndex) -> CalcResult {
|
||||||
if args.is_empty() {
|
|
||||||
return CalcResult::new_args_number_error(cell);
|
|
||||||
}
|
|
||||||
let mut result = false;
|
let mut result = false;
|
||||||
for arg in args {
|
for arg in args {
|
||||||
match self.evaluate_node_in_context(arg, cell) {
|
match self.evaluate_node_in_context(arg, cell) {
|
||||||
|
|||||||
@@ -140,7 +140,6 @@ pub enum Function {
|
|||||||
Countifs,
|
Countifs,
|
||||||
Maxifs,
|
Maxifs,
|
||||||
Minifs,
|
Minifs,
|
||||||
Geomean,
|
|
||||||
|
|
||||||
// Date and time
|
// Date and time
|
||||||
Date,
|
Date,
|
||||||
@@ -249,7 +248,7 @@ pub enum Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
pub fn into_iter() -> IntoIter<Function, 195> {
|
pub fn into_iter() -> IntoIter<Function, 194> {
|
||||||
[
|
[
|
||||||
Function::And,
|
Function::And,
|
||||||
Function::False,
|
Function::False,
|
||||||
@@ -349,7 +348,6 @@ impl Function {
|
|||||||
Function::Countifs,
|
Function::Countifs,
|
||||||
Function::Maxifs,
|
Function::Maxifs,
|
||||||
Function::Minifs,
|
Function::Minifs,
|
||||||
Function::Geomean,
|
|
||||||
Function::Year,
|
Function::Year,
|
||||||
Function::Day,
|
Function::Day,
|
||||||
Function::Month,
|
Function::Month,
|
||||||
@@ -613,7 +611,6 @@ impl Function {
|
|||||||
"COUNTIFS" => Some(Function::Countifs),
|
"COUNTIFS" => Some(Function::Countifs),
|
||||||
"MAXIFS" | "_XLFN.MAXIFS" => Some(Function::Maxifs),
|
"MAXIFS" | "_XLFN.MAXIFS" => Some(Function::Maxifs),
|
||||||
"MINIFS" | "_XLFN.MINIFS" => Some(Function::Minifs),
|
"MINIFS" | "_XLFN.MINIFS" => Some(Function::Minifs),
|
||||||
"GEOMEAN" => Some(Function::Geomean),
|
|
||||||
// Date and Time
|
// Date and Time
|
||||||
"YEAR" => Some(Function::Year),
|
"YEAR" => Some(Function::Year),
|
||||||
"DAY" => Some(Function::Day),
|
"DAY" => Some(Function::Day),
|
||||||
@@ -821,7 +818,6 @@ impl fmt::Display for Function {
|
|||||||
Function::Countifs => write!(f, "COUNTIFS"),
|
Function::Countifs => write!(f, "COUNTIFS"),
|
||||||
Function::Maxifs => write!(f, "MAXIFS"),
|
Function::Maxifs => write!(f, "MAXIFS"),
|
||||||
Function::Minifs => write!(f, "MINIFS"),
|
Function::Minifs => write!(f, "MINIFS"),
|
||||||
Function::Geomean => write!(f, "GEOMEAN"),
|
|
||||||
Function::Year => write!(f, "YEAR"),
|
Function::Year => write!(f, "YEAR"),
|
||||||
Function::Day => write!(f, "DAY"),
|
Function::Day => write!(f, "DAY"),
|
||||||
Function::Month => write!(f, "MONTH"),
|
Function::Month => write!(f, "MONTH"),
|
||||||
@@ -1058,7 +1054,6 @@ impl Model {
|
|||||||
Function::Countifs => self.fn_countifs(args, cell),
|
Function::Countifs => self.fn_countifs(args, cell),
|
||||||
Function::Maxifs => self.fn_maxifs(args, cell),
|
Function::Maxifs => self.fn_maxifs(args, cell),
|
||||||
Function::Minifs => self.fn_minifs(args, cell),
|
Function::Minifs => self.fn_minifs(args, cell),
|
||||||
Function::Geomean => self.fn_geomean(args, cell),
|
|
||||||
// Date and Time
|
// Date and Time
|
||||||
Function::Year => self.fn_year(args, cell),
|
Function::Year => self.fn_year(args, cell),
|
||||||
Function::Day => self.fn_day(args, cell),
|
Function::Day => self.fn_day(args, cell),
|
||||||
|
|||||||
@@ -635,85 +635,4 @@ impl Model {
|
|||||||
}
|
}
|
||||||
CalcResult::Number(max)
|
CalcResult::Number(max)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fn_geomean(&mut self, args: &[Node], cell: CellReferenceIndex) -> CalcResult {
|
|
||||||
if args.is_empty() {
|
|
||||||
return CalcResult::new_args_number_error(cell);
|
|
||||||
}
|
|
||||||
let mut count = 0.0;
|
|
||||||
let mut product = 1.0;
|
|
||||||
for arg in args {
|
|
||||||
match self.evaluate_node_in_context(arg, cell) {
|
|
||||||
CalcResult::Number(value) => {
|
|
||||||
count += 1.0;
|
|
||||||
product *= value;
|
|
||||||
}
|
|
||||||
CalcResult::Boolean(b) => {
|
|
||||||
if let Node::ReferenceKind { .. } = arg {
|
|
||||||
} else {
|
|
||||||
product *= if b { 1.0 } else { 0.0 };
|
|
||||||
count += 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CalcResult::Range { left, right } => {
|
|
||||||
if left.sheet != right.sheet {
|
|
||||||
return CalcResult::new_error(
|
|
||||||
Error::VALUE,
|
|
||||||
cell,
|
|
||||||
"Ranges are in different sheets".to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for row in left.row..(right.row + 1) {
|
|
||||||
for column in left.column..(right.column + 1) {
|
|
||||||
match self.evaluate_cell(CellReferenceIndex {
|
|
||||||
sheet: left.sheet,
|
|
||||||
row,
|
|
||||||
column,
|
|
||||||
}) {
|
|
||||||
CalcResult::Number(value) => {
|
|
||||||
count += 1.0;
|
|
||||||
product *= value;
|
|
||||||
}
|
|
||||||
error @ CalcResult::Error { .. } => return error,
|
|
||||||
CalcResult::Range { .. } => {
|
|
||||||
return CalcResult::new_error(
|
|
||||||
Error::ERROR,
|
|
||||||
cell,
|
|
||||||
"Unexpected Range".to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error @ CalcResult::Error { .. } => return error,
|
|
||||||
CalcResult::String(s) => {
|
|
||||||
if let Node::ReferenceKind { .. } = arg {
|
|
||||||
// Do nothing
|
|
||||||
} else if let Ok(t) = s.parse::<f64>() {
|
|
||||||
product *= t;
|
|
||||||
count += 1.0;
|
|
||||||
} else {
|
|
||||||
return CalcResult::Error {
|
|
||||||
error: Error::VALUE,
|
|
||||||
origin: cell,
|
|
||||||
message: "Argument cannot be cast into number".to_string(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Ignore everything else
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if count == 0.0 {
|
|
||||||
return CalcResult::Error {
|
|
||||||
error: Error::DIV,
|
|
||||||
origin: cell,
|
|
||||||
message: "Division by Zero".to_string(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
CalcResult::Number(product.powf(1.0 / count))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
token::{get_error_by_name, Error, OpCompare, OpProduct, OpSum, OpUnary},
|
token::{get_error_by_name, Error, OpCompare, OpProduct, OpSum, OpUnary},
|
||||||
types::*,
|
types::*,
|
||||||
utils::{self, is_valid_column_number, is_valid_row},
|
utils::{self, is_valid_column_number, is_valid_row, parse_reference_a1},
|
||||||
},
|
},
|
||||||
formatter::{
|
formatter::{
|
||||||
format::{format_number, parse_formatted_number},
|
format::{format_number, parse_formatted_number},
|
||||||
@@ -418,7 +418,6 @@ impl Model {
|
|||||||
CalcResult::new_error(Error::NIMPL, cell, "Arrays not implemented".to_string())
|
CalcResult::new_error(Error::NIMPL, cell, "Arrays not implemented".to_string())
|
||||||
}
|
}
|
||||||
VariableKind(defined_name) => {
|
VariableKind(defined_name) => {
|
||||||
println!("{:?}", defined_name);
|
|
||||||
let parsed_defined_name = self
|
let parsed_defined_name = self
|
||||||
.parsed_defined_names
|
.parsed_defined_names
|
||||||
.get(&(Some(cell.sheet), defined_name.to_lowercase())) // try getting local defined name
|
.get(&(Some(cell.sheet), defined_name.to_lowercase())) // try getting local defined name
|
||||||
@@ -427,11 +426,9 @@ impl Model {
|
|||||||
.get(&(None, defined_name.to_lowercase()))
|
.get(&(None, defined_name.to_lowercase()))
|
||||||
}); // fallback to global
|
}); // fallback to global
|
||||||
|
|
||||||
println!("Parsed: {:?}", defined_name);
|
|
||||||
if let Some(parsed_defined_name) = parsed_defined_name {
|
if let Some(parsed_defined_name) = parsed_defined_name {
|
||||||
match parsed_defined_name {
|
match parsed_defined_name {
|
||||||
ParsedDefinedName::CellReference(reference) => {
|
ParsedDefinedName::CellReference(reference) => {
|
||||||
println!("Here: {}", reference);
|
|
||||||
self.evaluate_cell(*reference)
|
self.evaluate_cell(*reference)
|
||||||
}
|
}
|
||||||
ParsedDefinedName::RangeReference(range) => CalcResult::Range {
|
ParsedDefinedName::RangeReference(range) => CalcResult::Range {
|
||||||
@@ -750,6 +747,29 @@ impl Model {
|
|||||||
self.workbook.worksheet(sheet)?.is_empty_cell(row, column)
|
self.workbook.worksheet(sheet)?.is_empty_cell(row, column)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns 'true' if the cell belongs to any Merged cells
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use ironcalc_base::Model;
|
||||||
|
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/// let mut model = Model::new_empty("model", "en", "UTC")?;
|
||||||
|
/// model.merge_cells(0, "A1:D5");
|
||||||
|
/// assert_eq!(model.is_part_of_merged_cells(0, 1, 2)?, true);
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn is_part_of_merged_cells(
|
||||||
|
&self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
) -> Result<bool, String> {
|
||||||
|
self.workbook
|
||||||
|
.worksheet(sheet)?
|
||||||
|
.is_part_of_merged_cells(row, column)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn evaluate_cell(&mut self, cell_reference: CellReferenceIndex) -> CalcResult {
|
pub(crate) fn evaluate_cell(&mut self, cell_reference: CellReferenceIndex) -> CalcResult {
|
||||||
let row_data = match self.workbook.worksheets[cell_reference.sheet as usize]
|
let row_data = match self.workbook.worksheets[cell_reference.sheet as usize]
|
||||||
.sheet_data
|
.sheet_data
|
||||||
@@ -1228,6 +1248,14 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
value: &str,
|
value: &str,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
||||||
let new_style_index;
|
let new_style_index;
|
||||||
if common::value_needs_quoting(value, &self.language) {
|
if common::value_needs_quoting(value, &self.language) {
|
||||||
@@ -1278,6 +1306,15 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
value: bool,
|
value: bool,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
||||||
let new_style_index = if self.workbook.styles.style_is_quote_prefix(style_index) {
|
let new_style_index = if self.workbook.styles.style_is_quote_prefix(style_index) {
|
||||||
self.workbook
|
self.workbook
|
||||||
@@ -1320,6 +1357,14 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
value: f64,
|
value: f64,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
||||||
let new_style_index = if self.workbook.styles.style_is_quote_prefix(style_index) {
|
let new_style_index = if self.workbook.styles.style_is_quote_prefix(style_index) {
|
||||||
self.workbook
|
self.workbook
|
||||||
@@ -1365,6 +1410,12 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
formula: String,
|
formula: String,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
let mut style_index = self.get_cell_style_index(sheet, row, column)?;
|
let mut style_index = self.get_cell_style_index(sheet, row, column)?;
|
||||||
if self.workbook.styles.style_is_quote_prefix(style_index) {
|
if self.workbook.styles.style_is_quote_prefix(style_index) {
|
||||||
style_index = self
|
style_index = self
|
||||||
@@ -1417,6 +1468,14 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
value: String,
|
value: String,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
// If value starts with "'" then we force the style to be quote_prefix
|
// If value starts with "'" then we force the style to be quote_prefix
|
||||||
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
let style_index = self.get_cell_style_index(sheet, row, column)?;
|
||||||
if let Some(new_value) = value.strip_prefix('\'') {
|
if let Some(new_value) = value.strip_prefix('\'') {
|
||||||
@@ -1931,6 +1990,7 @@ impl Model {
|
|||||||
/// Sets the number of frozen rows to `frozen_rows` in the workbook.
|
/// Sets the number of frozen rows to `frozen_rows` in the workbook.
|
||||||
/// Fails if `frozen`_rows` is either too small (<0) or too large (>LAST_ROW)`
|
/// Fails if `frozen`_rows` is either too small (<0) or too large (>LAST_ROW)`
|
||||||
pub fn set_frozen_rows(&mut self, sheet: u32, frozen_rows: i32) -> Result<(), String> {
|
pub fn set_frozen_rows(&mut self, sheet: u32, frozen_rows: i32) -> Result<(), String> {
|
||||||
|
// TODO: What is frozen rows and do we need to take of this if row we are frozing is part of merge cells ?
|
||||||
if let Some(worksheet) = self.workbook.worksheets.get_mut(sheet as usize) {
|
if let Some(worksheet) = self.workbook.worksheets.get_mut(sheet as usize) {
|
||||||
if frozen_rows < 0 {
|
if frozen_rows < 0 {
|
||||||
return Err("Frozen rows cannot be negative".to_string());
|
return Err("Frozen rows cannot be negative".to_string());
|
||||||
@@ -1948,6 +2008,7 @@ impl Model {
|
|||||||
/// Sets the number of frozen columns to `frozen_column` in the workbook.
|
/// Sets the number of frozen columns to `frozen_column` in the workbook.
|
||||||
/// Fails if `frozen`_columns` is either too small (<0) or too large (>LAST_COLUMN)`
|
/// Fails if `frozen`_columns` is either too small (<0) or too large (>LAST_COLUMN)`
|
||||||
pub fn set_frozen_columns(&mut self, sheet: u32, frozen_columns: i32) -> Result<(), String> {
|
pub fn set_frozen_columns(&mut self, sheet: u32, frozen_columns: i32) -> Result<(), String> {
|
||||||
|
// TODO: What is frozen columns and do we need to take of this if column we are frozing is part of merge cells ?
|
||||||
if let Some(worksheet) = self.workbook.worksheets.get_mut(sheet as usize) {
|
if let Some(worksheet) = self.workbook.worksheets.get_mut(sheet as usize) {
|
||||||
if frozen_columns < 0 {
|
if frozen_columns < 0 {
|
||||||
return Err("Frozen columns cannot be negative".to_string());
|
return Err("Frozen columns cannot be negative".to_string());
|
||||||
@@ -1990,93 +2051,162 @@ impl Model {
|
|||||||
.set_row_height(column, height)
|
.set_row_height(column, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new defined name
|
fn parse_merged_range(&mut self, range: &str) -> Result<(i32, i32, i32, i32), String> {
|
||||||
pub fn new_defined_name(
|
let parts: Vec<&str> = range.split(':').collect();
|
||||||
&mut self,
|
if parts.len() == 1 {
|
||||||
name: &str,
|
Err(format!("Invalid range: '{}'", range))
|
||||||
scope: Option<u32>,
|
} else if parts.len() == 2 {
|
||||||
formula: &str,
|
match (parse_reference_a1(parts[0]), parse_reference_a1(parts[1])) {
|
||||||
) -> Result<(), String> {
|
(Some(left), Some(right)) => {
|
||||||
let name_upper = name.to_uppercase();
|
return Ok((left.row, left.column, right.row, right.column));
|
||||||
let defined_names = &self.workbook.defined_names;
|
}
|
||||||
// if the defined name already exist return error
|
_ => return Err(format!("Invalid range: '{}'", range)),
|
||||||
for df in defined_names {
|
}
|
||||||
if df.name.to_uppercase() == name_upper && df.sheet_id == scope {
|
} else {
|
||||||
return Err("Defined name already exists".to_string());
|
return Err(format!("Invalid range: '{}'", range));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementing public APIS related to Merge cells handling
|
||||||
|
|
||||||
|
/// Merges given selected cells
|
||||||
|
/// If no overlap, it will create that merged cells with left most top cell value representing the whole merged cells
|
||||||
|
/// If new merge cells creation overlaps with any of the existing merged cells, Overlapped merged cells gets unmerged
|
||||||
|
/// and new merge cells gets added
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use ironcalc_base::Model;
|
||||||
|
/// # use ironcalc_base::cell::CellValue;
|
||||||
|
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/// let mut model = Model::new_empty("model", "en", "UTC")?;
|
||||||
|
/// model.merge_cells(0, "D4:F6").unwrap();
|
||||||
|
/// model.merge_cells(0, "A1:B4").unwrap();
|
||||||
|
/// assert_eq!(model.workbook.worksheet(0).unwrap().merged_cells_list.len(), 2);
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
/// * [Model::update_cell_with_formula()]
|
||||||
|
/// * [Model::update_cell_with_number()]
|
||||||
|
/// * [Model::update_cell_with_bool()]
|
||||||
|
/// * [Model::update_cell_with_text()]
|
||||||
|
pub fn merge_cells(&mut self, sheet: u32, range_ref: &str) -> Result<(), String> {
|
||||||
|
match self.parse_merged_range(range_ref) {
|
||||||
|
Ok(parsed_merge_cell_range) => {
|
||||||
|
// ATTENTION 2: Below thing we can support here but keeping it simple
|
||||||
|
// Web or different client needs to keep this in mind
|
||||||
|
// User can give errored parse ranges like C3:A1
|
||||||
|
// Where col_start and row_start and is greated then col_end and row_end
|
||||||
|
// Return error in these scenario
|
||||||
|
if parsed_merge_cell_range.0 > parsed_merge_cell_range.2
|
||||||
|
|| parsed_merge_cell_range.1 > parsed_merge_cell_range.3
|
||||||
|
{
|
||||||
|
return Err(
|
||||||
|
"Invalid parse range. Merge Mother cell always be top left cell"
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut merged_cells_overlaped_list: Vec<bool> = Vec::new();
|
||||||
|
// checking whether our new range overlaps with any of the already existing merged cells
|
||||||
|
// if so, need to unmerge those and create this new one
|
||||||
|
{
|
||||||
|
let worksheet = self.workbook.worksheet(sheet)?;
|
||||||
|
let merged_cells = worksheet.get_merged_cells_list();
|
||||||
|
|
||||||
|
for merge_node in merged_cells {
|
||||||
|
// checking whether any overlapping exist with this merge cell
|
||||||
|
if !(parsed_merge_cell_range.1 > merge_node.3
|
||||||
|
|| parsed_merge_cell_range.3 < merge_node.1
|
||||||
|
|| parsed_merge_cell_range.0 > merge_node.2
|
||||||
|
|| parsed_merge_cell_range.2 < merge_node.0)
|
||||||
|
{
|
||||||
|
// overlap has happened
|
||||||
|
merged_cells_overlaped_list.push(true);
|
||||||
|
} else {
|
||||||
|
merged_cells_overlaped_list.push(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !merged_cells_overlaped_list.is_empty() {
|
||||||
|
// Lets take Mutable ref to Merge cell and deletes all those nodes which has overlapped
|
||||||
|
let worksheet = self.workbook.worksheet_mut(sheet)?;
|
||||||
|
let merged_cells_list_mut = worksheet.get_merged_cells_list_mut();
|
||||||
|
let mut merged_cells_overlaped_list_iter = merged_cells_overlaped_list.iter();
|
||||||
|
merged_cells_list_mut
|
||||||
|
.retain(|_| !(*merged_cells_overlaped_list_iter.next().unwrap()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now need to update (n*m - 1) cells with empty cell ( except the Mother cell )
|
||||||
|
for row_index in parsed_merge_cell_range.0..=parsed_merge_cell_range.2 {
|
||||||
|
for col_index in parsed_merge_cell_range.1..=parsed_merge_cell_range.3 {
|
||||||
|
// skip Mother cell
|
||||||
|
if row_index == parsed_merge_cell_range.0
|
||||||
|
&& col_index == parsed_merge_cell_range.2
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the node with empty cell
|
||||||
|
{
|
||||||
|
self.workbook.worksheet_mut(sheet)?.update_cell(
|
||||||
|
row_index,
|
||||||
|
col_index,
|
||||||
|
Cell::EmptyCell { s: 0 },
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_merged_cells = MergedCells::new(parsed_merge_cell_range);
|
||||||
|
{
|
||||||
|
self.workbook
|
||||||
|
.worksheet_mut(sheet)?
|
||||||
|
.merged_cells_list
|
||||||
|
.push(new_merged_cells);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.workbook.defined_names.push(DefinedName {
|
|
||||||
name: name.to_string(),
|
|
||||||
formula: formula.to_string(),
|
|
||||||
sheet_id: scope,
|
|
||||||
});
|
|
||||||
self.reset_parsed_structures();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete defined name of name and scope
|
/// Unmerges a given/selected merged cells
|
||||||
pub fn delete_defined_name(&mut self, name: &str, scope: Option<u32>) -> Result<(), String> {
|
/// Once unmerged, only top most left corner value gets retained and all the others will have empty cell
|
||||||
let name_upper = name.to_uppercase();
|
/// # Examples
|
||||||
let defined_names = &self.workbook.defined_names;
|
///
|
||||||
let mut index = None;
|
/// ```rust
|
||||||
for (i, df) in defined_names.iter().enumerate() {
|
/// # use ironcalc_base::Model;
|
||||||
if df.name.to_uppercase() == name_upper && df.sheet_id == scope {
|
/// # use ironcalc_base::cell::CellValue;
|
||||||
index = Some(i);
|
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/// let mut model = Model::new_empty("model", "en", "UTC")?;
|
||||||
|
/// model.merge_cells(0, "D4:F6");
|
||||||
|
/// model.unmerge_cells(0, "D4:F6");
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn unmerge_cells(&mut self, sheet: u32, range_ref: &str) -> Result<(), String> {
|
||||||
|
let worksheet = self.workbook.worksheet(sheet)?;
|
||||||
|
let merged_cells = worksheet.get_merged_cells_list();
|
||||||
|
for (index, merge_node) in merged_cells.iter().enumerate() {
|
||||||
|
let merge_block_range_ref = merge_node.get_merged_cells_str_ref()?;
|
||||||
|
// finding the merge cell node to be deleted
|
||||||
|
if merge_block_range_ref.as_str() == range_ref {
|
||||||
|
// Merge cell to be deleted is found
|
||||||
|
self.workbook
|
||||||
|
.worksheet_mut(sheet)?
|
||||||
|
.merged_cells_list
|
||||||
|
.remove(index);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(i) = index {
|
Err("Invalid merge_cell_ref, Merged cells to be deleted is not found".to_string())
|
||||||
self.workbook.defined_names.remove(i);
|
|
||||||
self.reset_parsed_structures();
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err("Defined name not found".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// returns the formula for a defined name
|
|
||||||
pub fn get_defined_name_formula(
|
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
) -> Result<String, String> {
|
|
||||||
let name_upper = name.to_uppercase();
|
|
||||||
let defined_names = &self.workbook.defined_names;
|
|
||||||
for df in defined_names {
|
|
||||||
if df.name.to_uppercase() == name_upper && df.sheet_id == scope {
|
|
||||||
return Ok(df.formula.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err("Defined name not found".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// update defined name
|
|
||||||
pub fn update_defined_name(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
new_name: &str,
|
|
||||||
new_scope: Option<u32>,
|
|
||||||
new_formula: &str,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let name_upper = name.to_uppercase();
|
|
||||||
let defined_names = &self.workbook.defined_names;
|
|
||||||
let mut index = None;
|
|
||||||
for (i, df) in defined_names.iter().enumerate() {
|
|
||||||
if df.name.to_uppercase() == name_upper && df.sheet_id == scope {
|
|
||||||
index = Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(i) = index {
|
|
||||||
if let Some(df) = self.workbook.defined_names.get_mut(i) {
|
|
||||||
df.name = new_name.to_string();
|
|
||||||
df.sheet_id = new_scope;
|
|
||||||
df.formula = new_formula.to_string();
|
|
||||||
self.reset_parsed_structures();
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err("Defined name not found".to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
calc_result::Range,
|
calc_result::Range,
|
||||||
constants::{DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH},
|
constants::{DEFAULT_WINDOW_HEIGH, DEFAULT_WINDOW_WIDTH},
|
||||||
expressions::{
|
expressions::{
|
||||||
lexer::LexerMode,
|
lexer::LexerMode,
|
||||||
parser::{
|
parser::{
|
||||||
@@ -57,7 +57,7 @@ impl Model {
|
|||||||
rows: vec![],
|
rows: vec![],
|
||||||
comments: vec![],
|
comments: vec![],
|
||||||
dimension: "A1".to_string(),
|
dimension: "A1".to_string(),
|
||||||
merge_cells: vec![],
|
merged_cells_list: vec![],
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
shared_formulas: vec![],
|
shared_formulas: vec![],
|
||||||
sheet_data: Default::default(),
|
sheet_data: Default::default(),
|
||||||
@@ -359,7 +359,7 @@ impl Model {
|
|||||||
WorkbookView {
|
WorkbookView {
|
||||||
sheet: 0,
|
sheet: 0,
|
||||||
window_width: DEFAULT_WINDOW_WIDTH,
|
window_width: DEFAULT_WINDOW_WIDTH,
|
||||||
window_height: DEFAULT_WINDOW_HEIGHT,
|
window_height: DEFAULT_WINDOW_HEIGH,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,14 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
style: &Style,
|
style: &Style,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
let style_index = self.workbook.styles.get_style_index_or_create(style);
|
let style_index = self.workbook.styles.get_style_index_or_create(style);
|
||||||
self.workbook
|
self.workbook
|
||||||
.worksheet_mut(sheet)?
|
.worksheet_mut(sheet)?
|
||||||
@@ -252,6 +260,14 @@ impl Model {
|
|||||||
column: i32,
|
column: i32,
|
||||||
style_name: &str,
|
style_name: &str,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
// Checking first whether cell we are updating is part of Merged cells
|
||||||
|
// if so returning with Err
|
||||||
|
if self.is_part_of_merged_cells(sheet, row, column)? {
|
||||||
|
return Err(format!(
|
||||||
|
"Cell row : {}, col : {} is part of merged cells block, so singular update to the cell is not possible",
|
||||||
|
row, column
|
||||||
|
));
|
||||||
|
}
|
||||||
let style_index = self.workbook.styles.get_style_index_by_name(style_name)?;
|
let style_index = self.workbook.styles.get_style_index_by_name(style_name)?;
|
||||||
self.workbook
|
self.workbook
|
||||||
.worksheet_mut(sheet)?
|
.worksheet_mut(sheet)?
|
||||||
|
|||||||
@@ -46,17 +46,14 @@ pub(crate) mod util;
|
|||||||
|
|
||||||
mod engineering;
|
mod engineering;
|
||||||
mod test_fn_offset;
|
mod test_fn_offset;
|
||||||
mod test_fn_or;
|
|
||||||
mod test_number_format;
|
mod test_number_format;
|
||||||
|
|
||||||
mod test_escape_quotes;
|
mod test_escape_quotes;
|
||||||
mod test_extend;
|
mod test_extend;
|
||||||
mod test_fn_fv;
|
|
||||||
mod test_fn_type;
|
mod test_fn_type;
|
||||||
mod test_frozen_rows_and_columns;
|
mod test_frozen_rows_and_columns;
|
||||||
mod test_geomean;
|
|
||||||
mod test_get_cell_content;
|
mod test_get_cell_content;
|
||||||
mod test_issue_155;
|
mod test_model_merge_cell_fns;
|
||||||
mod test_percentage;
|
mod test_percentage;
|
||||||
mod test_set_functions_error_handling;
|
mod test_set_functions_error_handling;
|
||||||
mod test_today;
|
mod test_today;
|
||||||
|
|||||||
@@ -82,21 +82,3 @@ fn test_column_width_higher_edge() {
|
|||||||
assert!((worksheet.get_column_width(17).unwrap() - DEFAULT_COLUMN_WIDTH).abs() < f64::EPSILON);
|
assert!((worksheet.get_column_width(17).unwrap() - DEFAULT_COLUMN_WIDTH).abs() < f64::EPSILON);
|
||||||
assert_eq!(model.get_cell_style_index(0, 23, 16), Ok(1));
|
assert_eq!(model.get_cell_style_index(0, 23, 16), Ok(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_column_width_negative() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
let result = model
|
|
||||||
.workbook
|
|
||||||
.worksheet_mut(0)
|
|
||||||
.unwrap()
|
|
||||||
.set_column_width(16, -1.0);
|
|
||||||
assert_eq!(result, Err("Can not set a negative width: -1".to_string()));
|
|
||||||
assert_eq!(model.workbook.worksheets[0].cols.len(), 0);
|
|
||||||
let worksheet = model.workbook.worksheet(0).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
(worksheet.get_column_width(16).unwrap()),
|
|
||||||
DEFAULT_COLUMN_WIDTH
|
|
||||||
);
|
|
||||||
assert_eq!(model.get_cell_style_index(0, 23, 16), Ok(0));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
use crate::test::util::new_empty_model;
|
use crate::test::util::new_empty_model;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple_cases() {}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wrong_number_of_arguments() {
|
fn wrong_number_of_arguments() {
|
||||||
let mut model = new_empty_model();
|
let mut model = new_empty_model();
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::test::util::new_empty_model;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn computation() {
|
|
||||||
let i2 = "=-C2*(1+D2)^E2-F2*((D2+1)*((1+D2)^E2-1))/D2";
|
|
||||||
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("C2", "1");
|
|
||||||
model._set("D2", "2");
|
|
||||||
model._set("E2", "3");
|
|
||||||
model._set("F2", "4");
|
|
||||||
|
|
||||||
model._set("I2", i2);
|
|
||||||
|
|
||||||
model.evaluate();
|
|
||||||
|
|
||||||
assert_eq!(model._get_text("I2"), "-183");
|
|
||||||
assert_eq!(model._get_formula("I2"), i2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn format_as_currency() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("C2", "1");
|
|
||||||
model._set("D2", "2");
|
|
||||||
model._set("E2", "3");
|
|
||||||
model._set("F2", "4");
|
|
||||||
|
|
||||||
model._set("I2", "=FV(D2,E2,F2,C2,1)");
|
|
||||||
|
|
||||||
model.evaluate();
|
|
||||||
|
|
||||||
assert_eq!(model._get_text("I2"), "-$183.00");
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::test::util::new_empty_model;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fn_or() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("A1", "=OR(1, 0)");
|
|
||||||
model._set("A2", "=OR(0, 0)");
|
|
||||||
model._set("A3", "=OR(true, false)");
|
|
||||||
model._set("A4", "=OR(false, false)");
|
|
||||||
|
|
||||||
model.evaluate();
|
|
||||||
assert_eq!(model._get_text("A1"), *"TRUE");
|
|
||||||
assert_eq!(model._get_text("A2"), *"FALSE");
|
|
||||||
assert_eq!(model._get_text("A3"), *"TRUE");
|
|
||||||
assert_eq!(model._get_text("A4"), *"FALSE");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fn_or_no_arguments() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("A1", "=OR()");
|
|
||||||
model.evaluate();
|
|
||||||
assert_eq!(model._get_text("A1"), *"#ERROR!");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fn_or_missing_arguments() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("A1", "=OR(,)");
|
|
||||||
model._set("A2", "=OR(,1)");
|
|
||||||
model.evaluate();
|
|
||||||
assert_eq!(model._get_text("A1"), *"FALSE");
|
|
||||||
assert_eq!(model._get_text("A2"), *"TRUE");
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
#![allow(clippy::unwrap_used)]
|
||||||
|
|
||||||
use crate::constants::DEFAULT_ROW_HEIGHT;
|
|
||||||
|
|
||||||
use crate::cell::CellValue;
|
use crate::cell::CellValue;
|
||||||
|
|
||||||
use crate::number_format::to_excel_precision_str;
|
use crate::number_format::to_excel_precision_str;
|
||||||
@@ -115,15 +113,6 @@ fn test_set_row_height() {
|
|||||||
worksheet.set_row_height(5, 5.0).unwrap();
|
worksheet.set_row_height(5, 5.0).unwrap();
|
||||||
let worksheet = model.workbook.worksheet(0).unwrap();
|
let worksheet = model.workbook.worksheet(0).unwrap();
|
||||||
assert!((5.0 - worksheet.row_height(5).unwrap()).abs() < f64::EPSILON);
|
assert!((5.0 - worksheet.row_height(5).unwrap()).abs() < f64::EPSILON);
|
||||||
|
|
||||||
let worksheet = model.workbook.worksheet_mut(0).unwrap();
|
|
||||||
let result = worksheet.set_row_height(6, -1.0);
|
|
||||||
assert_eq!(result, Err("Can not set a negative height: -1".to_string()));
|
|
||||||
|
|
||||||
assert_eq!(worksheet.row_height(6).unwrap(), DEFAULT_ROW_HEIGHT);
|
|
||||||
|
|
||||||
worksheet.set_row_height(6, 0.0).unwrap();
|
|
||||||
assert_eq!(worksheet.row_height(6).unwrap(), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::test::util::new_empty_model;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_fn_geomean_arguments() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("A1", "=GEOMEAN()");
|
|
||||||
model.evaluate();
|
|
||||||
|
|
||||||
assert_eq!(model._get_text("A1"), *"#ERROR!");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_fn_geomean_minimal() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("B1", "1");
|
|
||||||
model._set("B2", "2");
|
|
||||||
model._set("B3", "3");
|
|
||||||
model._set("B4", "'2");
|
|
||||||
// B5 is empty
|
|
||||||
model._set("B6", "true");
|
|
||||||
model._set("A1", "=GEOMEAN(B1:B6)");
|
|
||||||
model.evaluate();
|
|
||||||
|
|
||||||
assert_eq!(model._get_text("A1"), *"1.817120593");
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::test::util::new_empty_model;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn issue_155() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
model._set("A1", "1");
|
|
||||||
model._set("A2", "2");
|
|
||||||
model._set("B2", "=A$1:A2");
|
|
||||||
model.evaluate();
|
|
||||||
|
|
||||||
assert_eq!(model._get_formula("B2"), "=A$1:A2".to_string());
|
|
||||||
}
|
|
||||||
155
base/src/test/test_model_merge_cell_fns.rs
Normal file
155
base/src/test/test_model_merge_cell_fns.rs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#![allow(clippy::unwrap_used)]
|
||||||
|
|
||||||
|
use crate::{test::util::new_empty_model, types::CellType};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_model_set_fns_related_to_merge_cells() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
|
||||||
|
// creating a merge cell of D1:F2
|
||||||
|
model.merge_cells(0, "D1:F2").unwrap();
|
||||||
|
|
||||||
|
// Updating the mother cell of Merge cells and expecting the update to go through
|
||||||
|
model.set_user_input(0, 1, 4, "Hello".to_string()).unwrap();
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 4).unwrap(), "Hello");
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 4).unwrap(), CellType::Text);
|
||||||
|
|
||||||
|
// Updating cell which is not in Merge cell block
|
||||||
|
assert_eq!(model.set_user_input(0, 1, 3, "Hello".to_string()), Ok(()));
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 3), Ok("Hello".to_string()));
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 3), Ok(CellType::Text));
|
||||||
|
|
||||||
|
// 1: testing with set_user_input()
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.set_user_input(0, 1, 5, "Hello".to_string()),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 5), Ok("".to_string()));
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 5), Ok(CellType::Number));
|
||||||
|
|
||||||
|
// 2: testing with update_cell_with_bool()
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.update_cell_with_bool(0, 1, 5, true),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 5), Ok("".to_string()));
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 5), Ok(CellType::Number));
|
||||||
|
|
||||||
|
// 3: testing with update_cell_with_formula()
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.update_cell_with_formula(0, 1, 5, "=SUM(A1+A2)".to_string()),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 5), Ok(CellType::Number));
|
||||||
|
|
||||||
|
// 4: testing with update_cell_with_number()
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.update_cell_with_number(0, 1, 5, 10.0),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 5), Ok("".to_string()));
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 5), Ok(CellType::Number));
|
||||||
|
|
||||||
|
// 5: testing with update_cell_with_text()
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.update_cell_with_text(0, 1, 5, "new text"),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_cell_content(0, 1, 5), Ok("".to_string()));
|
||||||
|
assert_eq!(model.get_cell_type(0, 1, 5), Ok(CellType::Number));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_model_merge_cells_crud_api() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
|
||||||
|
// creating a merge cell of D4:F6
|
||||||
|
model.merge_cells(0, "D4:F6").unwrap();
|
||||||
|
model
|
||||||
|
.set_user_input(0, 4, 4, "Merge Block".to_string())
|
||||||
|
.unwrap();
|
||||||
|
// CRUD APIS testing on Merge Cells
|
||||||
|
|
||||||
|
// Case1: Creating a new merge cell without overlapping
|
||||||
|
// Newly created Merge block is left to D4:F6
|
||||||
|
assert_eq!(model.merge_cells(0, "A1:B4"), Ok(()));
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.worksheet(0).unwrap().merged_cells_list.len(),
|
||||||
|
2
|
||||||
|
);
|
||||||
|
model.set_user_input(0, 1, 1, "left".to_string()).unwrap();
|
||||||
|
|
||||||
|
// Newly created Merge block is right to D4:F6
|
||||||
|
assert_eq!(model.merge_cells(0, "G1:H7"), Ok(()));
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.worksheet(0).unwrap().merged_cells_list.len(),
|
||||||
|
3
|
||||||
|
);
|
||||||
|
model.set_user_input(0, 1, 7, "right".to_string()).unwrap();
|
||||||
|
|
||||||
|
// Newly created Merge block is above to D4:F6
|
||||||
|
assert_eq!(model.merge_cells(0, "C1:D3"), Ok(()));
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.worksheet(0).unwrap().merged_cells_list.len(),
|
||||||
|
4
|
||||||
|
);
|
||||||
|
model.set_user_input(0, 1, 3, "top".to_string()).unwrap();
|
||||||
|
|
||||||
|
// Newly created Merge block is down to D4:F6
|
||||||
|
assert_eq!(model.merge_cells(0, "D8:E9"), Ok(()));
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.worksheet(0).unwrap().merged_cells_list.len(),
|
||||||
|
5
|
||||||
|
);
|
||||||
|
model.set_user_input(0, 8, 4, "down".to_string()).unwrap();
|
||||||
|
|
||||||
|
// Case2: Creating a new merge cell with overlapping with other 3 merged cell
|
||||||
|
assert_eq!(model.merge_cells(0, "C1:G4"), Ok(()));
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.worksheet(0).unwrap().merged_cells_list.len(),
|
||||||
|
3
|
||||||
|
);
|
||||||
|
model
|
||||||
|
.set_user_input(0, 1, 3, "overlapped_new_merge_block".to_string())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Case3: Giving wrong parsing range
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "C3:A1"),
|
||||||
|
Err("Invalid parse range. Merge Mother cell always be top left cell".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "CA:A1"),
|
||||||
|
Err("Invalid range: 'CA:A1'".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "C0:A1"),
|
||||||
|
Err("Invalid range: 'C0:A1'".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "C1:A0"),
|
||||||
|
Err("Invalid range: 'C1:A0'".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "C1"),
|
||||||
|
Err("Invalid range: 'C1'".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
model.merge_cells(0, "C1:A1:B1"),
|
||||||
|
Err("Invalid range: 'C1:A1:B1'".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Case3: Giving wrong merge_ref, which would resulting in error (Merge cell to be deleted is not found)
|
||||||
|
assert_eq!(
|
||||||
|
model.unmerge_cells(0, "C1:E1"),
|
||||||
|
Err("Invalid merge_cell_ref, Merged cells to be deleted is not found".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Case4: unmerge scenario
|
||||||
|
assert_eq!(model.unmerge_cells(0, "C1:G4"), Ok(()));
|
||||||
|
}
|
||||||
@@ -62,3 +62,45 @@ fn test_create_named_style() {
|
|||||||
let style = model.get_style_for_cell(0, 1, 1).unwrap();
|
let style = model.get_style_for_cell(0, 1, 1).unwrap();
|
||||||
assert!(style.font.b);
|
assert!(style.font.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_model_style_set_fns_in_merge_cell_context() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
|
||||||
|
// creating a merge cell of D1:F2
|
||||||
|
model.merge_cells(0, "D1:F2").unwrap();
|
||||||
|
model.set_user_input(0, 1, 4, "Hello".to_string()).unwrap();
|
||||||
|
|
||||||
|
let mut style = model.get_style_for_cell(0, 1, 1).unwrap();
|
||||||
|
assert!(!style.font.b);
|
||||||
|
style.font.b = true;
|
||||||
|
|
||||||
|
// Updating the mother cell of Merge cells and expecting the update to go through
|
||||||
|
// This should make the text "Hello" in bold format
|
||||||
|
assert_eq!(model.set_cell_style(0, 1, 4, &style), Ok(()));
|
||||||
|
|
||||||
|
// 1: testing with set_cell_style()
|
||||||
|
let original_style: Style = model.get_style_for_cell(0, 1, 5).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.set_cell_style(0, 1, 5, &style),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_style_for_cell(0, 1, 5), Ok(original_style));
|
||||||
|
|
||||||
|
// 2: testing with set_cell_style_by_name
|
||||||
|
let mut style = model.get_style_for_cell(0, 1, 4).unwrap();
|
||||||
|
style.font.b = true;
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.styles.create_named_style("bold", &style),
|
||||||
|
Ok(())
|
||||||
|
);
|
||||||
|
|
||||||
|
let original_style: Style = model.get_style_for_cell(0, 1, 5).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.set_cell_style_by_name(0, 1, 5, "bold"),
|
||||||
|
Err("Cell row : 1, col : 5 is part of merged cells block, so singular update to the cell is not possible".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(model.get_style_for_cell(0, 1, 5), Ok(original_style));
|
||||||
|
}
|
||||||
|
|||||||
@@ -283,3 +283,87 @@ fn test_worksheet_navigate_to_edge_in_direction() {
|
|||||||
assert_eq!(navigate(8, 3, NavigationDirection::Up), (6, 3));
|
assert_eq!(navigate(8, 3, NavigationDirection::Up), (6, 3));
|
||||||
assert_eq!(navigate(9, 3, NavigationDirection::Up), (6, 3));
|
assert_eq!(navigate(9, 3, NavigationDirection::Up), (6, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests Merge cells related functions of worksheet
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_merge_cell_fns_worksheet() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
|
||||||
|
// Adding one Merge cell
|
||||||
|
model.merge_cells(0, "D1:E3").unwrap();
|
||||||
|
|
||||||
|
// Lets check whether D1 (Mother Merge cell) is part of Merge block or not
|
||||||
|
// It should not be considered as part of Merge cell
|
||||||
|
assert!(!model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.is_part_of_merged_cells(1, 4)
|
||||||
|
.unwrap(),);
|
||||||
|
|
||||||
|
// Lets give cell which is actually part of Merge block and expect true from fn
|
||||||
|
assert!(model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.is_part_of_merged_cells(2, 4)
|
||||||
|
.unwrap());
|
||||||
|
|
||||||
|
// Lets give cell which is not a part of Merge block and expect false from fn
|
||||||
|
assert!(!model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.is_part_of_merged_cells(2, 6)
|
||||||
|
.unwrap());
|
||||||
|
|
||||||
|
// Lets give an Invalid row
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.is_part_of_merged_cells(0, 1),
|
||||||
|
Err("Incorrect row or column".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
//Lets give Invalid column
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.is_part_of_merged_cells(1, 0),
|
||||||
|
Err("Incorrect row or column".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verifying get fns of worksheet
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.get_merged_cells_list()
|
||||||
|
.len(),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
{
|
||||||
|
let merge_cell_vec = model
|
||||||
|
.workbook
|
||||||
|
.worksheet_mut(0)
|
||||||
|
.unwrap()
|
||||||
|
.get_merged_cells_list_mut();
|
||||||
|
merge_cell_vec.remove(0);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.get_merged_cells_list()
|
||||||
|
.len(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ mod test_autofill_columns;
|
|||||||
mod test_autofill_rows;
|
mod test_autofill_rows;
|
||||||
mod test_border;
|
mod test_border;
|
||||||
mod test_clear_cells;
|
mod test_clear_cells;
|
||||||
mod test_defined_names;
|
|
||||||
mod test_diff_queue;
|
mod test_diff_queue;
|
||||||
mod test_evaluation;
|
mod test_evaluation;
|
||||||
mod test_general;
|
mod test_general;
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::UserModel;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_defined_name() {
|
|
||||||
let mut model = UserModel::new_empty("model", "en", "UTC").unwrap();
|
|
||||||
model.set_user_input(0, 1, 1, "42").unwrap();
|
|
||||||
model.new_defined_name("myName", None, "$A$1").unwrap();
|
|
||||||
model.set_user_input(0, 5, 7, "=myName").unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
model.get_formatted_cell_value(0, 5, 7),
|
|
||||||
Ok("42".to_string())
|
|
||||||
);
|
|
||||||
|
|
||||||
// rename it
|
|
||||||
model
|
|
||||||
.update_defined_name("myName", None, "myName", None, "$A$1*2")
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
model.get_formatted_cell_value(0, 5, 7),
|
|
||||||
Ok("42".to_string())
|
|
||||||
);
|
|
||||||
|
|
||||||
// delete it
|
|
||||||
model.delete_defined_name("myName", None).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
model.get_formatted_cell_value(0, 5, 7),
|
|
||||||
Ok("#REF!".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rename_defined_name() {}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn delete_sheet() {}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn change_scope() {}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::{
|
constants::{
|
||||||
DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH,
|
DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, DEFAULT_WINDOW_HEIGH, DEFAULT_WINDOW_WIDTH,
|
||||||
LAST_COLUMN,
|
LAST_COLUMN,
|
||||||
},
|
},
|
||||||
test::util::new_empty_model,
|
test::util::new_empty_model,
|
||||||
@@ -87,7 +87,7 @@ fn last_colum() {
|
|||||||
fn page_down() {
|
fn page_down() {
|
||||||
let model = new_empty_model();
|
let model = new_empty_model();
|
||||||
let mut model = UserModel::from_model(model);
|
let mut model = UserModel::from_model(model);
|
||||||
let window_height = DEFAULT_WINDOW_HEIGHT as f64;
|
let window_height = DEFAULT_WINDOW_HEIGH as f64;
|
||||||
let row_height = DEFAULT_ROW_HEIGHT;
|
let row_height = DEFAULT_ROW_HEIGHT;
|
||||||
let row_count = f64::floor(window_height / row_height) as i32;
|
let row_count = f64::floor(window_height / row_height) as i32;
|
||||||
model.on_page_down().unwrap();
|
model.on_page_down().unwrap();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
#![allow(clippy::unwrap_used)]
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::{DEFAULT_ROW_HEIGHT, DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH},
|
constants::{DEFAULT_ROW_HEIGHT, DEFAULT_WINDOW_HEIGH, DEFAULT_WINDOW_WIDTH},
|
||||||
test::util::new_empty_model,
|
test::util::new_empty_model,
|
||||||
UserModel,
|
UserModel,
|
||||||
};
|
};
|
||||||
@@ -11,7 +11,7 @@ fn basic_test() {
|
|||||||
let model = new_empty_model();
|
let model = new_empty_model();
|
||||||
let mut model = UserModel::from_model(model);
|
let mut model = UserModel::from_model(model);
|
||||||
let window_height = model.get_window_height().unwrap();
|
let window_height = model.get_window_height().unwrap();
|
||||||
assert_eq!(window_height, DEFAULT_WINDOW_HEIGHT);
|
assert_eq!(window_height, DEFAULT_WINDOW_HEIGH);
|
||||||
|
|
||||||
let window_width = model.get_window_width().unwrap();
|
let window_width = model.get_window_width().unwrap();
|
||||||
assert_eq!(window_width, DEFAULT_WINDOW_WIDTH);
|
assert_eq!(window_width, DEFAULT_WINDOW_WIDTH);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{collections::HashMap, fmt::Display};
|
use std::{collections::HashMap, fmt::Display};
|
||||||
|
|
||||||
use crate::expressions::token::Error;
|
use crate::expressions::token::Error;
|
||||||
|
use crate::expressions::utils::number_to_column;
|
||||||
|
|
||||||
fn default_as_false() -> bool {
|
fn default_as_false() -> bool {
|
||||||
false
|
false
|
||||||
@@ -35,7 +36,7 @@ pub struct WorkbookView {
|
|||||||
pub sheet: u32,
|
pub sheet: u32,
|
||||||
/// The current width of the window
|
/// The current width of the window
|
||||||
pub window_width: i64,
|
pub window_width: i64,
|
||||||
/// The current height of the window
|
/// The current heigh of the window
|
||||||
pub window_height: i64,
|
pub window_height: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ pub struct Worksheet {
|
|||||||
pub sheet_id: u32,
|
pub sheet_id: u32,
|
||||||
pub state: SheetState,
|
pub state: SheetState,
|
||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
pub merge_cells: Vec<String>,
|
pub merged_cells_list: Vec<MergedCells>,
|
||||||
pub comments: Vec<Comment>,
|
pub comments: Vec<Comment>,
|
||||||
pub frozen_rows: i32,
|
pub frozen_rows: i32,
|
||||||
pub frozen_columns: i32,
|
pub frozen_columns: i32,
|
||||||
@@ -351,6 +352,43 @@ pub enum FontScheme {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MergedCells type
|
||||||
|
// There will be one MergedCells struct maintained for every Merged cells that we load
|
||||||
|
// merge_cell_range : Its tuple having [row_start, column_start, row_end, column_end]
|
||||||
|
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
|
pub struct MergedCells(pub i32, pub i32, pub i32, pub i32);
|
||||||
|
|
||||||
|
// implementing accessor function
|
||||||
|
impl MergedCells {
|
||||||
|
// Method which returns range_ref from the tuple
|
||||||
|
// ex : (3,1,4,2) is interpreted as A3:B4
|
||||||
|
pub fn get_merged_cells_str_ref(&self) -> Result<String, String> {
|
||||||
|
let start_column = number_to_column(self.1).ok_or(format!(
|
||||||
|
"Error while converting column start {} number to column string ref",
|
||||||
|
self.1
|
||||||
|
))?;
|
||||||
|
let end_column = number_to_column(self.3).ok_or(format!(
|
||||||
|
"Error while converting column end {} number to column string ref",
|
||||||
|
self.3
|
||||||
|
))?;
|
||||||
|
return Ok(start_column
|
||||||
|
+ &self.0.to_string()
|
||||||
|
+ &":".to_string()
|
||||||
|
+ &end_column
|
||||||
|
+ &self.2.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only Public function where Merge cell can be created
|
||||||
|
pub fn new(merge_cell_parsed_range: (i32, i32, i32, i32)) -> Self {
|
||||||
|
Self(
|
||||||
|
merge_cell_parsed_range.0,
|
||||||
|
merge_cell_parsed_range.1,
|
||||||
|
merge_cell_parsed_range.2,
|
||||||
|
merge_cell_parsed_range.3,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for FontScheme {
|
impl Display for FontScheme {
|
||||||
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -309,7 +309,6 @@ impl Model {
|
|||||||
Function::Sum => self.units_fn_sum_like(args, cell),
|
Function::Sum => self.units_fn_sum_like(args, cell),
|
||||||
Function::Average => self.units_fn_sum_like(args, cell),
|
Function::Average => self.units_fn_sum_like(args, cell),
|
||||||
Function::Pmt => self.units_fn_currency(args, cell),
|
Function::Pmt => self.units_fn_currency(args, cell),
|
||||||
Function::Fv => self.units_fn_currency(args, cell),
|
|
||||||
Function::Nper => self.units_fn_currency(args, cell),
|
Function::Nper => self.units_fn_currency(args, cell),
|
||||||
Function::Npv => self.units_fn_currency(args, cell),
|
Function::Npv => self.units_fn_currency(args, cell),
|
||||||
Function::Irr => self.units_fn_percentage(args, cell),
|
Function::Irr => self.units_fn_percentage(args, cell),
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
model::Model,
|
model::Model,
|
||||||
types::{
|
types::{
|
||||||
Alignment, BorderItem, CellType, Col, DefinedName, HorizontalAlignment, SheetProperties,
|
Alignment, BorderItem, CellType, Col, HorizontalAlignment, SheetProperties, Style,
|
||||||
Style, VerticalAlignment,
|
VerticalAlignment,
|
||||||
},
|
},
|
||||||
utils::is_valid_hex_color,
|
utils::is_valid_hex_color,
|
||||||
};
|
};
|
||||||
@@ -342,7 +342,7 @@ impl UserModel {
|
|||||||
old_value: Box::new(old_value),
|
old_value: Box::new(old_value),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let line_count = value.split('\n').count();
|
let line_count = value.split("\n").count();
|
||||||
let row_height = self.model.get_row_height(sheet, row)?;
|
let row_height = self.model.get_row_height(sheet, row)?;
|
||||||
let cell_height = (line_count as f64) * DEFAULT_ROW_HEIGHT;
|
let cell_height = (line_count as f64) * DEFAULT_ROW_HEIGHT;
|
||||||
if cell_height > row_height {
|
if cell_height > row_height {
|
||||||
@@ -713,7 +713,7 @@ impl UserModel {
|
|||||||
|
|
||||||
/// Paste `styles` in the selected area
|
/// Paste `styles` in the selected area
|
||||||
pub fn on_paste_styles(&mut self, styles: &[Vec<Style>]) -> Result<(), String> {
|
pub fn on_paste_styles(&mut self, styles: &[Vec<Style>]) -> Result<(), String> {
|
||||||
let styles_height = styles.len() as i32;
|
let styles_heigh = styles.len() as i32;
|
||||||
let styles_width = styles[0].len() as i32;
|
let styles_width = styles[0].len() as i32;
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
||||||
view.sheet
|
view.sheet
|
||||||
@@ -732,13 +732,13 @@ impl UserModel {
|
|||||||
|
|
||||||
// If the pasted area is smaller than the selected area we increase it
|
// If the pasted area is smaller than the selected area we increase it
|
||||||
let [row_start, column_start, row_end, column_end] = range;
|
let [row_start, column_start, row_end, column_end] = range;
|
||||||
let last_row = row_end.max(row_start + styles_height - 1);
|
let last_row = row_end.max(row_start + styles_heigh - 1);
|
||||||
let last_column = column_end.max(column_start + styles_width - 1);
|
let last_column = column_end.max(column_start + styles_width - 1);
|
||||||
|
|
||||||
let mut diff_list = Vec::new();
|
let mut diff_list = Vec::new();
|
||||||
for row in row_start..=last_row {
|
for row in row_start..=last_row {
|
||||||
for column in column_start..=last_column {
|
for column in column_start..=last_column {
|
||||||
let row_index = ((row - row_start) % styles_height) as usize;
|
let row_index = ((row - row_start) % styles_heigh) as usize;
|
||||||
let column_index = ((column - column_start) % styles_width) as usize;
|
let column_index = ((column - column_start) % styles_width) as usize;
|
||||||
let style = &styles[row_index][column_index];
|
let style = &styles[row_index][column_index];
|
||||||
let old_value = self.model.get_style_for_cell(sheet, row, column)?;
|
let old_value = self.model.get_style_for_cell(sheet, row, column)?;
|
||||||
@@ -1689,66 +1689,6 @@ impl UserModel {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of defined names
|
|
||||||
pub fn get_defined_name_list(&self) -> Vec<DefinedName> {
|
|
||||||
self.model.workbook.defined_names.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Delete an existing defined name
|
|
||||||
pub fn delete_defined_name(&mut self, name: &str, scope: Option<u32>) -> Result<(), String> {
|
|
||||||
let old_value = self.model.get_defined_name_formula(name, scope)?;
|
|
||||||
let diff_list = vec![Diff::DeleteDefinedName {
|
|
||||||
name: name.to_string(),
|
|
||||||
scope,
|
|
||||||
old_value,
|
|
||||||
}];
|
|
||||||
self.push_diff_list(diff_list);
|
|
||||||
self.model.delete_defined_name(name, scope)?;
|
|
||||||
self.evaluate_if_not_paused();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new defined name
|
|
||||||
pub fn new_defined_name(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
formula: &str,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
self.model.new_defined_name(name, scope, formula)?;
|
|
||||||
let diff_list = vec![Diff::CreateDefinedName {
|
|
||||||
name: name.to_string(),
|
|
||||||
scope,
|
|
||||||
value: formula.to_string(),
|
|
||||||
}];
|
|
||||||
self.push_diff_list(diff_list);
|
|
||||||
self.evaluate_if_not_paused();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates a defined name
|
|
||||||
pub fn update_defined_name(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
new_name: &str,
|
|
||||||
new_scope: Option<u32>,
|
|
||||||
new_formula: &str,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let old_formula = self.model.get_defined_name_formula(name, scope)?;
|
|
||||||
let diff_list = vec![Diff::UpdateDefinedName {
|
|
||||||
name: name.to_string(),
|
|
||||||
scope,
|
|
||||||
old_formula: old_formula.to_string(),
|
|
||||||
new_name: new_name.to_string(),
|
|
||||||
new_scope,
|
|
||||||
new_formula: new_formula.to_string(),
|
|
||||||
}];
|
|
||||||
self.push_diff_list(diff_list);
|
|
||||||
self.evaluate_if_not_paused();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// **** Private methods ****** //
|
// **** Private methods ****** //
|
||||||
|
|
||||||
fn push_diff_list(&mut self, diff_list: DiffList) {
|
fn push_diff_list(&mut self, diff_list: DiffList) {
|
||||||
@@ -1919,20 +1859,6 @@ impl UserModel {
|
|||||||
} => {
|
} => {
|
||||||
self.model.set_show_grid_lines(*sheet, *old_value)?;
|
self.model.set_show_grid_lines(*sheet, *old_value)?;
|
||||||
}
|
}
|
||||||
Diff::CreateDefinedName { name, scope, value } => todo!(),
|
|
||||||
Diff::DeleteDefinedName {
|
|
||||||
name,
|
|
||||||
scope,
|
|
||||||
old_value,
|
|
||||||
} => todo!(),
|
|
||||||
Diff::UpdateDefinedName {
|
|
||||||
name,
|
|
||||||
scope,
|
|
||||||
old_formula,
|
|
||||||
new_name,
|
|
||||||
new_scope,
|
|
||||||
new_formula,
|
|
||||||
} => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if needs_evaluation {
|
if needs_evaluation {
|
||||||
@@ -2060,20 +1986,6 @@ impl UserModel {
|
|||||||
} => {
|
} => {
|
||||||
self.model.set_show_grid_lines(*sheet, *new_value)?;
|
self.model.set_show_grid_lines(*sheet, *new_value)?;
|
||||||
}
|
}
|
||||||
Diff::CreateDefinedName { name, scope, value } => todo!(),
|
|
||||||
Diff::DeleteDefinedName {
|
|
||||||
name,
|
|
||||||
scope,
|
|
||||||
old_value,
|
|
||||||
} => todo!(),
|
|
||||||
Diff::UpdateDefinedName {
|
|
||||||
name,
|
|
||||||
scope,
|
|
||||||
old_formula,
|
|
||||||
new_name,
|
|
||||||
new_scope,
|
|
||||||
new_formula,
|
|
||||||
} => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,26 +108,7 @@ pub(crate) enum Diff {
|
|||||||
sheet: u32,
|
sheet: u32,
|
||||||
old_value: bool,
|
old_value: bool,
|
||||||
new_value: bool,
|
new_value: bool,
|
||||||
},
|
}, // FIXME: we are missing SetViewDiffs
|
||||||
CreateDefinedName {
|
|
||||||
name: String,
|
|
||||||
scope: Option<u32>,
|
|
||||||
value: String,
|
|
||||||
},
|
|
||||||
DeleteDefinedName {
|
|
||||||
name: String,
|
|
||||||
scope: Option<u32>,
|
|
||||||
old_value: String,
|
|
||||||
},
|
|
||||||
UpdateDefinedName {
|
|
||||||
name: String,
|
|
||||||
scope: Option<u32>,
|
|
||||||
old_formula: String,
|
|
||||||
new_name: String,
|
|
||||||
new_scope: Option<u32>,
|
|
||||||
new_formula: String,
|
|
||||||
},
|
|
||||||
// FIXME: we are missing SetViewDiffs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type DiffList = Vec<Diff>;
|
pub(crate) type DiffList = Vec<Diff>;
|
||||||
|
|||||||
@@ -255,14 +255,11 @@ impl Worksheet {
|
|||||||
/// * If the row does not a have a style we add it.
|
/// * If the row does not a have a style we add it.
|
||||||
/// * If it has we modify the height and make sure it is applied.
|
/// * If it has we modify the height and make sure it is applied.
|
||||||
///
|
///
|
||||||
/// Fails if row index is outside allowed range or height is negative.
|
/// Fails if column index is outside allowed range.
|
||||||
pub fn set_row_height(&mut self, row: i32, height: f64) -> Result<(), String> {
|
pub fn set_row_height(&mut self, row: i32, height: f64) -> Result<(), String> {
|
||||||
if !is_valid_row(row) {
|
if !is_valid_row(row) {
|
||||||
return Err(format!("Row number '{row}' is not valid."));
|
return Err(format!("Row number '{row}' is not valid."));
|
||||||
}
|
}
|
||||||
if height < 0.0 {
|
|
||||||
return Err(format!("Can not set a negative height: {height}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let rows = &mut self.rows;
|
let rows = &mut self.rows;
|
||||||
for r in rows.iter_mut() {
|
for r in rows.iter_mut() {
|
||||||
@@ -287,7 +284,7 @@ impl Worksheet {
|
|||||||
/// * If the column does not a have a width we simply add it
|
/// * If the column does not a have a width we simply add it
|
||||||
/// * If it has, it might be part of a range and we ned to split the range.
|
/// * If it has, it might be part of a range and we ned to split the range.
|
||||||
///
|
///
|
||||||
/// Fails if column index is outside allowed range or width is negative.
|
/// Fails if column index is outside allowed range.
|
||||||
pub fn set_column_width(&mut self, column: i32, width: f64) -> Result<(), String> {
|
pub fn set_column_width(&mut self, column: i32, width: f64) -> Result<(), String> {
|
||||||
self.set_column_width_and_style(column, width, None)
|
self.set_column_width_and_style(column, width, None)
|
||||||
}
|
}
|
||||||
@@ -301,9 +298,6 @@ impl Worksheet {
|
|||||||
if !is_valid_column_number(column) {
|
if !is_valid_column_number(column) {
|
||||||
return Err(format!("Column number '{column}' is not valid."));
|
return Err(format!("Column number '{column}' is not valid."));
|
||||||
}
|
}
|
||||||
if width < 0.0 {
|
|
||||||
return Err(format!("Can not set a negative width: {width}"));
|
|
||||||
}
|
|
||||||
let cols = &mut self.cols;
|
let cols = &mut self.cols;
|
||||||
let mut col = Col {
|
let mut col = Col {
|
||||||
min: column,
|
min: column,
|
||||||
@@ -530,6 +524,23 @@ impl Worksheet {
|
|||||||
Ok(is_empty)
|
Ok(is_empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if cell part of Merged Cells.
|
||||||
|
/// First cell of Merged cells block is not considered as part of Merged cells
|
||||||
|
/// Ex : if Merged cells were A1-C3, A1 is not considered as part of Merged cells block
|
||||||
|
pub fn is_part_of_merged_cells(&self, row: i32, column: i32) -> Result<bool, String> {
|
||||||
|
if !is_valid_column_number(column) || !is_valid_row(row) {
|
||||||
|
return Err("Incorrect row or column".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// traverse through Vector of Merged Cells and return (linear search)
|
||||||
|
for merged_cells in &self.merged_cells_list {
|
||||||
|
if merged_cells.is_cell_part_of_merged_cells(row, column) {
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
|
||||||
/// It provides convenient method for user navigation in the spreadsheet by jumping to edges.
|
/// It provides convenient method for user navigation in the spreadsheet by jumping to edges.
|
||||||
/// Spreadsheet engines usually allow this method of navigation by using CTRL+arrows.
|
/// Spreadsheet engines usually allow this method of navigation by using CTRL+arrows.
|
||||||
/// Behaviour summary:
|
/// Behaviour summary:
|
||||||
@@ -583,6 +594,16 @@ impl Worksheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns mutable reference to Vector of Merged cells list
|
||||||
|
pub fn get_merged_cells_list_mut(&mut self) -> &mut Vec<MergedCells> {
|
||||||
|
&mut self.merged_cells_list
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns reference to Vector of Merged cells list
|
||||||
|
pub fn get_merged_cells_list(&self) -> &Vec<MergedCells> {
|
||||||
|
&self.merged_cells_list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WalkFoundCells {
|
struct WalkFoundCells {
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ use xlsx::import;
|
|||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
use crate::types::PyCellType;
|
|
||||||
|
|
||||||
create_exception!(_ironcalc, WorkbookError, PyException);
|
create_exception!(_ironcalc, WorkbookError, PyException);
|
||||||
|
|
||||||
/// This is a model implementing the 'raw' API
|
/// This is a model implementing the 'raw' API
|
||||||
@@ -60,21 +58,6 @@ impl PyModel {
|
|||||||
|
|
||||||
// Get values
|
// Get values
|
||||||
|
|
||||||
/// Get raw value
|
|
||||||
pub fn get_cell_content(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
|
|
||||||
self.model
|
|
||||||
.get_cell_content(sheet, row, column)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get cell type
|
|
||||||
pub fn get_cell_type(&self, sheet: u32, row: i32, column: i32) -> PyResult<PyCellType> {
|
|
||||||
self.model
|
|
||||||
.get_cell_type(sheet, row, column)
|
|
||||||
.map(|cell_type| cell_type.into())
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get formatted value
|
/// Get formatted value
|
||||||
pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
|
pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
|
||||||
self.model
|
self.model
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use xlsx::base::types::{
|
use xlsx::base::types::{
|
||||||
Alignment, Border, BorderItem, BorderStyle, CellType, Fill, Font, FontScheme,
|
Alignment, Border, BorderItem, BorderStyle, Fill, Font, FontScheme, HorizontalAlignment, Style,
|
||||||
HorizontalAlignment, Style, VerticalAlignment,
|
VerticalAlignment,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -161,17 +161,6 @@ pub struct PyFill {
|
|||||||
pub bg_color: Option<String>,
|
pub bg_color: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyclass(eq, eq_int)]
|
|
||||||
#[derive(PartialEq, Clone)]
|
|
||||||
pub enum PyCellType {
|
|
||||||
Number = 1,
|
|
||||||
Text = 2,
|
|
||||||
LogicalValue = 4,
|
|
||||||
ErrorValue = 16,
|
|
||||||
Array = 64,
|
|
||||||
CompoundData = 128,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Conversions from references to Py* types to non-Py types
|
// Conversions from references to Py* types to non-Py types
|
||||||
|
|
||||||
// Enums
|
// Enums
|
||||||
@@ -437,31 +426,3 @@ impl From<Style> for PyStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversion from PyCellType to CellType
|
|
||||||
impl From<PyCellType> for CellType {
|
|
||||||
fn from(py_cell_type: PyCellType) -> Self {
|
|
||||||
match py_cell_type {
|
|
||||||
PyCellType::Number => CellType::Number,
|
|
||||||
PyCellType::Text => CellType::Text,
|
|
||||||
PyCellType::LogicalValue => CellType::LogicalValue,
|
|
||||||
PyCellType::ErrorValue => CellType::ErrorValue,
|
|
||||||
PyCellType::Array => CellType::Array,
|
|
||||||
PyCellType::CompoundData => CellType::CompoundData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Conversion from CellType to PyCellType
|
|
||||||
impl From<CellType> for PyCellType {
|
|
||||||
fn from(cell_type: CellType) -> Self {
|
|
||||||
match cell_type {
|
|
||||||
CellType::Number => PyCellType::Number,
|
|
||||||
CellType::Text => PyCellType::Text,
|
|
||||||
CellType::LogicalValue => PyCellType::LogicalValue,
|
|
||||||
CellType::ErrorValue => PyCellType::ErrorValue,
|
|
||||||
CellType::Array => PyCellType::Array,
|
|
||||||
CellType::CompoundData => PyCellType::CompoundData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use serde::Serialize;
|
|
||||||
use wasm_bindgen::{
|
use wasm_bindgen::{
|
||||||
prelude::{wasm_bindgen, JsError},
|
prelude::{wasm_bindgen, JsError},
|
||||||
JsValue,
|
JsValue,
|
||||||
@@ -30,13 +29,6 @@ pub fn column_name_from_number(column: i32) -> Result<String, JsError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct DefinedName {
|
|
||||||
name: String,
|
|
||||||
scope: Option<u32>,
|
|
||||||
formula: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
model: BaseModel,
|
model: BaseModel,
|
||||||
@@ -549,43 +541,4 @@ impl Model {
|
|||||||
.paste_csv_string(&range, csv)
|
.paste_csv_string(&range, csv)
|
||||||
.map_err(|e| to_js_error(e.to_string()))
|
.map_err(|e| to_js_error(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "getDefinedNameList")]
|
|
||||||
pub fn get_defined_name_list(&self) -> Result<JsValue, JsError> {
|
|
||||||
let data: DefinedNameList =
|
|
||||||
self.model
|
|
||||||
.get_defined_name_list()
|
|
||||||
.iter()
|
|
||||||
.map(|s| DefinedName {
|
|
||||||
name: s.name.to_string(),
|
|
||||||
scope: s.sheet_id,
|
|
||||||
formula: s.formula.to_string(),
|
|
||||||
});
|
|
||||||
// Ok(data)
|
|
||||||
serde_wasm_bindgen::to_value(&data).map_err(|e| to_js_error(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "newDefinedName")]
|
|
||||||
pub fn new_defined_name(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
formula: &str,
|
|
||||||
) -> Result<(), JsError> {
|
|
||||||
self.model
|
|
||||||
.new_defined_name(name, scope, formula)
|
|
||||||
.map_err(|e| to_js_error(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "updateDefinedName")]
|
|
||||||
pub fn update_defined_name(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
scope: Option<u32>,
|
|
||||||
new_name: &str,
|
|
||||||
new_scope: Option<u32>,
|
|
||||||
new_formula: &str,
|
|
||||||
) -> Result<(), JsError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2003,7 +2003,7 @@ export default defineConfig({
|
|||||||
link: "/programming/python-bindings",
|
link: "/programming/python-bindings",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "JavaScript",
|
text: "JavScript",
|
||||||
link: "/programming/javascript-bindings",
|
link: "/programming/javascript-bindings",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,46 +4,8 @@ outline: deep
|
|||||||
lang: en-US
|
lang: en-US
|
||||||
---
|
---
|
||||||
|
|
||||||
# FV function
|
# FV
|
||||||
## Overview
|
|
||||||
FV (<u>F</u>uture <u>V</u>alue) is a function of the Financial category that can be used to predict the future value of an investment or asset based on its present value.
|
|
||||||
|
|
||||||
FV can be used to calculate future value over a specified number of compounding periods. A fixed interest rate or yield is assumed over all periods, and a fixed payment or deposit can be applied at the start or end of every period.
|
::: warning
|
||||||
|
🚧 This function is implemented but currently lacks detailed documentation. For guidance, you may refer to the equivalent functionality in [Microsoft Excel documentation](https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb).
|
||||||
If your interest rate varies between periods, use the [FVSCHEDULE](/functions/financial/fvschedule) function instead of FV.
|
:::
|
||||||
## Usage
|
|
||||||
### Syntax
|
|
||||||
**FV(rate, nper, pmt, pv, type)**
|
|
||||||
### Argument descriptions
|
|
||||||
* *rate*. The fixed percentage interest rate or yield per period.
|
|
||||||
* *nper*. The number of compounding periods to be taken into account. While this will often be an integer, non-integer values are accepted and processed.
|
|
||||||
* *pmt*. The fixed amount paid or deposited each compounding period.
|
|
||||||
* *pv* (optional). The present value or starting amount of the asset (default 0).
|
|
||||||
* *type* (optional). A logical value indicating whether the payment due dates are at the end (0) of the compounding periods or at the beginning (any non-zero value). The default is 0 when omitted.
|
|
||||||
### Additional guidance
|
|
||||||
* Make sure that the *rate* argument specifies the interest rate or yield applicable to the compounding period, based on the value chosen for *nper*.
|
|
||||||
* The *pmt* and *pv* arguments should be expressed in the same currency unit. The value returned is expressed in the same currency unit.
|
|
||||||
* To ensure a worthwhile result, one of the *pmt* and *pv* arguments should be non-zero.
|
|
||||||
* The setting of the *type* argument only affects the calculation for non-zero values of the *pmt* argument.
|
|
||||||
<!--@include: ../markdown-snippets/error-type-details.md-->
|
|
||||||
|
|
||||||
## Details
|
|
||||||
* If *rate* = 0, FV is given by the equation:
|
|
||||||
$$
|
|
||||||
FV = -pv - (pmt \times nper)
|
|
||||||
$$
|
|
||||||
|
|
||||||
* If *rate* <> 0 and *type* = 0, FV is given by the equation:
|
|
||||||
$$ FV = -pv \times (1 + rate)^{nper} - \dfrac{pmt\times\big({(1+rate)^{nper}-1}\big)}{rate}
|
|
||||||
$$
|
|
||||||
* If *rate* <> 0 and *type* <> 0, FV is given by the equation:
|
|
||||||
$$ FV = -pv \times (1 + rate)^{nper} - \dfrac{pmt\times\big({(1+rate)^{nper}-1}\big) \times(1+rate)}{rate}
|
|
||||||
$$
|
|
||||||
## Examples
|
|
||||||
[See this example in IronCalc](https://app.ironcalc.com/?example=fv).
|
|
||||||
|
|
||||||
## Links
|
|
||||||
* For more information about the concept of "future value" in finance, visit Wikipedia's [Future value](https://en.wikipedia.org/wiki/Future_value) page.
|
|
||||||
* See also IronCalc's [NPER](/functions/financial/nper), [PMT](/functions/financial/pmt), [PV](/functions/financial/pv) and [RATE](/functions/financial/rate) functions.
|
|
||||||
* Visit Microsoft Excel's [FV function](https://support.microsoft.com/en-gb/office/fv-function-2eef9f44-a084-4c61-bdd8-4fe4bb1b71b3) page.
|
|
||||||
* Both [Google Sheets](https://support.google.com/docs/answer/3093224) and [LibreOffice Calc](https://wiki.documentfoundation.org/Documentation/Calc_Functions/FV) provide versions of the FV function.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
* For information about the different types of errors that you may encounter when using IronCalc functions, visit our [Error Types](/features/error-types) page.
|
|
||||||
@@ -9,13 +9,13 @@ lang: en-US
|
|||||||
At the moment IronCalc only supports a few function in this section.
|
At the moment IronCalc only supports a few function in this section.
|
||||||
You can track the progress in this [GitHub issue](https://github.com/ironcalc/IronCalc/issues/55).
|
You can track the progress in this [GitHub issue](https://github.com/ironcalc/IronCalc/issues/55).
|
||||||
|
|
||||||
| Function | Status | Documentation |
|
| Function | Status | Documentation |
|
||||||
| ------------------------ |--------------------------------------------------| ------------- |
|
| ------------------------ | ---------------------------------------------- | ------------- |
|
||||||
| AVEDEV | <Badge type="info" text="Not implemented yet" /> | – |
|
| AVEDEV | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| AVERAGE | <Badge type="tip" text="Available" /> | – |
|
| AVERAGE | <Badge type="tip" text="Available" /> | – |
|
||||||
| AVERAGEA | <Badge type="tip" text="Available" /> | – |
|
| AVERAGEA | <Badge type="tip" text="Available" /> | – |
|
||||||
| AVERAGEIF | <Badge type="tip" text="Available" /> | – |
|
| AVERAGEIF | <Badge type="tip" text="Available" /> | – |
|
||||||
| AVERAGEIFS | <Badge type="tip" text="Available" /> | – |
|
| AVERAGEIFS | <Badge type="tip" text="Available" /> | – |
|
||||||
| BETA.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
| BETA.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| BETA.INV | <Badge type="info" text="Not implemented yet" /> | – |
|
| BETA.INV | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| BINOM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
| BINOM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
@@ -29,11 +29,11 @@ You can track the progress in this [GitHub issue](https://github.com/ironcalc/Ir
|
|||||||
| CONFIDENCE.NORM | <Badge type="info" text="Not implemented yet" /> | – |
|
| CONFIDENCE.NORM | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| CONFIDENCE.T | <Badge type="info" text="Not implemented yet" /> | – |
|
| CONFIDENCE.T | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| CORREL | <Badge type="info" text="Not implemented yet" /> | – |
|
| CORREL | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| COUNT | <Badge type="tip" text="Available" /> | – |
|
| COUNT | <Badge type="tip" text="Available" /> | – |
|
||||||
| COUNTA | <Badge type="tip" text="Available" /> | – |
|
| COUNTA | <Badge type="tip" text="Available" /> | – |
|
||||||
| COUNTBLANK | <Badge type="tip" text="Available" /> | – |
|
| COUNTBLANK | <Badge type="tip" text="Available" /> | – |
|
||||||
| COUNTIF | <Badge type="tip" text="Available" /> | – |
|
| COUNTIF | <Badge type="tip" text="Available" /> | – |
|
||||||
| COUNTIFS | <Badge type="tip" text="Available" /> | – |
|
| COUNTIFS | <Badge type="tip" text="Available" /> | – |
|
||||||
| COVARIANCE.P | <Badge type="info" text="Not implemented yet" /> | – |
|
| COVARIANCE.P | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| COVARIANCE.S | <Badge type="info" text="Not implemented yet" /> | – |
|
| COVARIANCE.S | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| DEVSQ | <Badge type="info" text="Not implemented yet" /> | – |
|
| DEVSQ | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
@@ -58,7 +58,7 @@ You can track the progress in this [GitHub issue](https://github.com/ironcalc/Ir
|
|||||||
| GAMMALN | <Badge type="info" text="Not implemented yet" /> | – |
|
| GAMMALN | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| GAMMALN.PRECISE | <Badge type="info" text="Not implemented yet" /> | – |
|
| GAMMALN.PRECISE | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| GAUSS | <Badge type="info" text="Not implemented yet" /> | – |
|
| GAUSS | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| GEOMEAN | <Badge type="info" text="Available" /> | – |
|
| GEOMEAN | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| GROWTH | <Badge type="info" text="Not implemented yet" /> | – |
|
| GROWTH | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| HARMEAN | <Badge type="info" text="Not implemented yet" /> | – |
|
| HARMEAN | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| HYPGEOM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
| HYPGEOM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
@@ -69,9 +69,9 @@ You can track the progress in this [GitHub issue](https://github.com/ironcalc/Ir
|
|||||||
| LOGEST | <Badge type="info" text="Not implemented yet" /> | – |
|
| LOGEST | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| LOGNORM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
| LOGNORM.DIST | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| LOGNORM.INV | <Badge type="info" text="Not implemented yet" /> | – |
|
| LOGNORM.INV | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| MAX | <Badge type="tip" text="Available" /> | – |
|
| MAX | <Badge type="tip" text="Available" /> | – |
|
||||||
| MAXA | <Badge type="info" text="Not implemented yet" /> | – |
|
| MAXA | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| MAXIFS | <Badge type="tip" text="Available" /> | – |
|
| MAXIFS | <Badge type="tip" text="Available" /> | – |
|
||||||
| MEDIAN | <Badge type="info" text="Not implemented yet" /> | – |
|
| MEDIAN | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| MODE.MULT | <Badge type="info" text="Not implemented yet" /> | – |
|
| MODE.MULT | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
| MODE.SNGL | <Badge type="info" text="Not implemented yet" /> | – |
|
| MODE.SNGL | <Badge type="info" text="Not implemented yet" /> | – |
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ lang: en-US
|
|||||||
# GEOMEAN
|
# GEOMEAN
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
🚧 This function is implemented but currently lacks detailed documentation. For guidance, you may refer to the equivalent functionality in [Microsoft Excel documentation](https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb).
|
🚧 This function is not yet available in IronCalc.
|
||||||
|
[Follow development here](https://github.com/ironcalc/IronCalc/labels/Functions)
|
||||||
:::
|
:::
|
||||||
@@ -35,11 +35,6 @@ export function FileBar(properties: {
|
|||||||
}}
|
}}
|
||||||
onDelete={properties.onDelete}
|
onDelete={properties.onDelete}
|
||||||
/>
|
/>
|
||||||
<HelpButton
|
|
||||||
onClick={() => window.open("https://docs.ironcalc.com", "_blank")}
|
|
||||||
>
|
|
||||||
Help
|
|
||||||
</HelpButton>
|
|
||||||
<WorkbookTitle
|
<WorkbookTitle
|
||||||
name={properties.model.getName()}
|
name={properties.model.getName()}
|
||||||
onNameChange={(name) => {
|
onNameChange={(name) => {
|
||||||
@@ -89,7 +84,7 @@ export function FileBar(properties: {
|
|||||||
|
|
||||||
const StyledDesktopLogo = styled(IronCalcLogo)`
|
const StyledDesktopLogo = styled(IronCalcLogo)`
|
||||||
width: 120px;
|
width: 120px;
|
||||||
margin-left: 12px;
|
margin-left: 10px;
|
||||||
@media (max-width: 769px) {
|
@media (max-width: 769px) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -103,19 +98,6 @@ const StyledIronCalcIcon = styled(IronCalcIcon)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HelpButton = styled("div")`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 12px;
|
|
||||||
font-family: Inter;
|
|
||||||
padding: 8px;
|
|
||||||
border-radius: 4px;
|
|
||||||
cursor: pointer;
|
|
||||||
&:hover {
|
|
||||||
background-color: #f2f2f2;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Toast = styled("div")`
|
const Toast = styled("div")`
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -125,7 +107,7 @@ const Toast = styled("div")`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const Divider = styled("div")`
|
const Divider = styled("div")`
|
||||||
margin: 0px 8px 0px 16px;
|
margin: 10px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
border-left: 1px solid #e0e0e0;
|
border-left: 1px solid #e0e0e0;
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import styled from "@emotion/styled";
|
import styled from "@emotion/styled";
|
||||||
import { Menu, MenuItem, Modal } from "@mui/material";
|
import { Menu, MenuItem, Modal } from "@mui/material";
|
||||||
import { Check, FileDown, FileUp, Plus, Trash2 } from "lucide-react";
|
import { FileDown, FileUp, Plus, Trash2 } from "lucide-react";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { UploadFileDialog } from "./UploadFileDialog";
|
import { UploadFileDialog } from "./UploadFileDialog";
|
||||||
import { getModelsMetadata, getSelectedUuid } from "./storage";
|
import { getModelsMetadata, getSelectedUuid } from "./storage";
|
||||||
@@ -29,9 +29,9 @@ export function FileMenu(props: {
|
|||||||
setMenuOpen(false);
|
setMenuOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CheckIndicator>
|
<span style={{ width: "20px" }}>
|
||||||
{uuid === selectedUuid ? <StyledCheck /> : ""}
|
{uuid === selectedUuid ? "•" : ""}
|
||||||
</CheckIndicator>
|
</span>
|
||||||
<MenuItemText
|
<MenuItemText
|
||||||
style={{
|
style={{
|
||||||
maxWidth: "240px",
|
maxWidth: "240px",
|
||||||
@@ -57,19 +57,9 @@ export function FileMenu(props: {
|
|||||||
open={isMenuOpen}
|
open={isMenuOpen}
|
||||||
onClose={(): void => setMenuOpen(false)}
|
onClose={(): void => setMenuOpen(false)}
|
||||||
anchorEl={anchorElement.current}
|
anchorEl={anchorElement.current}
|
||||||
sx={{
|
|
||||||
"& .MuiPaper-root": { borderRadius: "8px", padding: "4px 0px" },
|
|
||||||
"& .MuiList-root": { padding: "0" },
|
|
||||||
}}
|
|
||||||
|
|
||||||
// anchorOrigin={properties.anchorOrigin}
|
// anchorOrigin={properties.anchorOrigin}
|
||||||
>
|
>
|
||||||
<MenuItemWrapper
|
<MenuItemWrapper onClick={props.newModel}>
|
||||||
onClick={() => {
|
|
||||||
props.newModel();
|
|
||||||
setMenuOpen(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<StyledPlus />
|
<StyledPlus />
|
||||||
<MenuItemText>New</MenuItemText>
|
<MenuItemText>New</MenuItemText>
|
||||||
</MenuItemWrapper>
|
</MenuItemWrapper>
|
||||||
@@ -159,19 +149,12 @@ const StyledTrash = styled(Trash2)`
|
|||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledCheck = styled(Check)`
|
|
||||||
width: 16px;
|
|
||||||
height: 16px;
|
|
||||||
color: #333333;
|
|
||||||
padding-right: 10px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const MenuDivider = styled("div")`
|
const MenuDivider = styled("div")`
|
||||||
width: 100%;
|
width: 80%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
margin-top: 4px;
|
margin-top: 8px;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 8px;
|
||||||
border-top: 1px solid #eeeeee;
|
border-top: 1px solid #e0e0e0;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const MenuItemText = styled("div")`
|
const MenuItemText = styled("div")`
|
||||||
@@ -183,12 +166,7 @@ const MenuItemWrapper = styled(MenuItem)`
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
width: calc(100% - 8px);
|
width: 100%;
|
||||||
min-width: 172px;
|
|
||||||
margin: 0px 4px;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 8px;
|
|
||||||
height: 32px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const FileMenuWrapper = styled("div")`
|
const FileMenuWrapper = styled("div")`
|
||||||
@@ -196,16 +174,11 @@ const FileMenuWrapper = styled("div")`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-family: Inter;
|
font-family: Inter;
|
||||||
padding: 8px;
|
padding: 10px;
|
||||||
|
height: 20px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const CheckIndicator = styled("span")`
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
min-width: 26px;
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export function UploadFileDialog(properties: {
|
|||||||
width: 16,
|
width: 16,
|
||||||
color: "#EFAA6D",
|
color: "#EFAA6D",
|
||||||
backgroundColor: "#F2994A1A",
|
backgroundColor: "#F2994A1A",
|
||||||
padding: "2px 6px",
|
padding: "2px 4px",
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -192,13 +192,7 @@ export function UploadFileDialog(properties: {
|
|||||||
<BookOpen
|
<BookOpen
|
||||||
style={{ width: 16, height: 16, marginLeft: 12, marginRight: 8 }}
|
style={{ width: 16, height: 16, marginLeft: 12, marginRight: 8 }}
|
||||||
/>
|
/>
|
||||||
<UploadFooterLink
|
<span>Learn more about importing files into IronCalc</span>
|
||||||
href="https://docs.ironcalc.com/web-application/importing-files.html"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
Learn more about importing files into IronCalc
|
|
||||||
</UploadFooterLink>
|
|
||||||
</UploadFooter>
|
</UploadFooter>
|
||||||
</UploadDialog>
|
</UploadDialog>
|
||||||
);
|
);
|
||||||
@@ -208,46 +202,34 @@ const Cross = styled("div")`
|
|||||||
&:hover {
|
&:hover {
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
display: flex;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
height: 24px;
|
height: 16px;
|
||||||
width: 24px;
|
width: 16px;
|
||||||
cursor: pointer;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const DocLink = styled("span")`
|
const DocLink = styled("span")`
|
||||||
color: #f2994a;
|
color: #f2994a;
|
||||||
text-decoration: none;
|
text-decoration: underline;
|
||||||
&:hover {
|
&:hover {
|
||||||
text-decoration: underline;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const UploadFooter = styled("div")`
|
const UploadFooter = styled("div")`
|
||||||
height: 44px;
|
height: 40px;
|
||||||
border-top: 1px solid #e0e0e0;
|
border-top: 1px solid #e0e0e0;
|
||||||
color: #757575;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const UploadFooterLink = styled("a")`
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: #757575;
|
color: #757575;
|
||||||
text-decoration: none;
|
display: flex;
|
||||||
&:hover {
|
align-items: center;
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const UploadTitle = styled("div")`
|
const UploadTitle = styled("div")`
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-bottom: 1px solid #e0e0e0;
|
border-bottom: 1px solid #e0e0e0;
|
||||||
height: 44px;
|
height: 40px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
`;
|
`;
|
||||||
@@ -259,8 +241,7 @@ const UploadDialog = styled("div")`
|
|||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
width: 460px;
|
width: 455px;
|
||||||
max-width: 90%;
|
|
||||||
height: 285px;
|
height: 285px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border: 1px solid #e0e0e0;
|
border: 1px solid #e0e0e0;
|
||||||
@@ -270,16 +251,6 @@ const UploadDialog = styled("div")`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const DropZone = styled("div")`
|
const DropZone = styled("div")`
|
||||||
&:hover {
|
|
||||||
border: 1px dashed #f2994a;
|
|
||||||
transition: 0.2s ease-in-out;
|
|
||||||
gap: 8px;
|
|
||||||
background: linear-gradient(
|
|
||||||
180deg,
|
|
||||||
rgba(242, 153, 74, 0.12) 0%,
|
|
||||||
rgba(242, 153, 74, 0) 100%
|
|
||||||
);
|
|
||||||
}
|
|
||||||
flex-grow: 2;
|
flex-grow: 2;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -288,7 +259,7 @@ const DropZone = styled("div")`
|
|||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: #faebd7;
|
background-color: #faebd7;
|
||||||
border: 1px dashed #efaa6d;
|
border: 1px dashed #f2994a;
|
||||||
background: linear-gradient(
|
background: linear-gradient(
|
||||||
180deg,
|
180deg,
|
||||||
rgba(242, 153, 74, 0.08) 0%,
|
rgba(242, 153, 74, 0.08) 0%,
|
||||||
@@ -297,6 +268,4 @@ const DropZone = styled("div")`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
vertical-align: center;
|
vertical-align: center;
|
||||||
gap: 16px;
|
|
||||||
transition: 0.2s ease-in-out;
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -867,18 +867,14 @@ export default class WorksheetCanvas {
|
|||||||
frozenRows,
|
frozenRows,
|
||||||
frozenColumns,
|
frozenColumns,
|
||||||
);
|
);
|
||||||
if (frozenColumns > 0) {
|
xFrozenEnd += this.getColumnWidth(
|
||||||
xFrozenEnd += this.getColumnWidth(
|
this.model.getSelectedSheet(),
|
||||||
this.model.getSelectedSheet(),
|
frozenColumns,
|
||||||
frozenColumns,
|
);
|
||||||
);
|
yFrozenEnd += this.getRowHeight(
|
||||||
}
|
this.model.getSelectedSheet(),
|
||||||
if (frozenRows > 0) {
|
frozenRows,
|
||||||
yFrozenEnd += this.getRowHeight(
|
);
|
||||||
this.model.getSelectedSheet(),
|
|
||||||
frozenRows,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (startRow <= frozenRows && endRow > frozenRows) {
|
if (startRow <= frozenRows && endRow > frozenRows) {
|
||||||
yEnd = Math.max(yEnd, yFrozenEnd);
|
yEnd = Math.max(yEnd, yFrozenEnd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ const ColorPicker = (properties: ColorPickerProps) => {
|
|||||||
setColor(newColor);
|
setColor(newColor);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<HorizontalDivider />
|
|
||||||
<ColorPickerInput>
|
<ColorPickerInput>
|
||||||
<HexWrapper>
|
<HexWrapper>
|
||||||
<HexLabel>{"Hex"}</HexLabel>
|
<HexLabel>{"Hex"}</HexLabel>
|
||||||
@@ -132,8 +131,6 @@ const ColorPicker = (properties: ColorPickerProps) => {
|
|||||||
const RecentLabel = styled.div`
|
const RecentLabel = styled.div`
|
||||||
font-family: "Inter";
|
font-family: "Inter";
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-family: Inter;
|
|
||||||
margin: 8px 8px 0px 8px;
|
|
||||||
color: ${theme.palette.text.secondary};
|
color: ${theme.palette.text.secondary};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -141,17 +138,14 @@ const ColorList = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
margin: 8px;
|
|
||||||
justify-content: flex-start;
|
|
||||||
gap: 4.7px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Button = styled.button<{ $color: string }>`
|
const Button = styled.button<{ $color: string }>`
|
||||||
width: 16px;
|
width: 20px;
|
||||||
height: 16px;
|
height: 20px;
|
||||||
${({ $color }): string => {
|
${({ $color }): string => {
|
||||||
if ($color.toUpperCase() === "#FFFFFF") {
|
if ($color.toUpperCase() === "#FFFFFF") {
|
||||||
return `border: 1px solid ${theme.palette.grey["300"]};`;
|
return `border: 1px solid ${theme.palette.grey["600"]};`;
|
||||||
}
|
}
|
||||||
return `border: 1px solid ${$color};`;
|
return `border: 1px solid ${$color};`;
|
||||||
}}
|
}}
|
||||||
@@ -159,19 +153,17 @@ const Button = styled.button<{ $color: string }>`
|
|||||||
return $color;
|
return $color;
|
||||||
}};
|
}};
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
margin-top: 0px;
|
margin-top: 10px;
|
||||||
border-radius: 4px;
|
margin-right: 10px;
|
||||||
&:hover {
|
border-radius: 2px;
|
||||||
cursor: pointer;
|
|
||||||
outline: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
outline-offset: 1px;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HorizontalDivider = styled.div`
|
const HorizontalDivider = styled.div`
|
||||||
height: 0px;
|
height: 0px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-top: 1px solid ${theme.palette.grey["200"]};
|
border-top: 1px solid ${theme.palette.grey["400"]};
|
||||||
|
margin-top: 15px;
|
||||||
|
margin-bottom: 5px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// const StyledPopover = styled(Popover)`
|
// const StyledPopover = styled(Popover)`
|
||||||
@@ -191,7 +183,7 @@ const HorizontalDivider = styled.div`
|
|||||||
const ColorPickerDialog = styled.div`
|
const ColorPickerDialog = styled.div`
|
||||||
background: ${theme.palette.background.default};
|
background: ${theme.palette.background.default};
|
||||||
width: ${colorPickerWidth}px;
|
width: ${colorPickerWidth}px;
|
||||||
padding: 0px;
|
padding: 15px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
@@ -201,11 +193,11 @@ const ColorPickerDialog = styled.div`
|
|||||||
}
|
}
|
||||||
& .react-colorful__saturation {
|
& .react-colorful__saturation {
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
border-radius: 0px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
& .react-colorful__hue {
|
& .react-colorful__hue {
|
||||||
height: 8px;
|
height: 20px;
|
||||||
margin: 8px;
|
margin-top: 15px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
& .react-colorful__saturation-pointer {
|
& .react-colorful__saturation-pointer {
|
||||||
@@ -214,22 +206,19 @@ const ColorPickerDialog = styled.div`
|
|||||||
}
|
}
|
||||||
& .react-colorful__hue-pointer {
|
& .react-colorful__hue-pointer {
|
||||||
width: 7px;
|
width: 7px;
|
||||||
border-radius: 8px;
|
border-radius: 3px;
|
||||||
height: 16px;
|
|
||||||
width: 16px;
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HashLabel = styled.div`
|
const HashLabel = styled.div`
|
||||||
margin: auto 0px auto 10px;
|
margin: auto 0px auto 10px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #333;
|
color: #7d8ec2;
|
||||||
font-family: ${theme.typography.button.fontFamily};
|
font-family: ${theme.typography.button.fontFamily};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HexLabel = styled.div`
|
const HexLabel = styled.div`
|
||||||
margin: auto 0px;
|
margin: auto 10px auto 0px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
font-family: ${theme.typography.button.fontFamily};
|
font-family: ${theme.typography.button.fontFamily};
|
||||||
@@ -238,22 +227,15 @@ const HexLabel = styled.div`
|
|||||||
const HexColorInputBox = styled.div`
|
const HexColorInputBox = styled.div`
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
margin-right: 10px;
|
||||||
width: 140px;
|
width: 140px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
border: 1px solid ${theme.palette.grey["300"]};
|
border: 1px solid ${theme.palette.grey["600"]};
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
&:hover {
|
|
||||||
border: 1px solid ${theme.palette.grey["600"]};
|
|
||||||
}
|
|
||||||
&:focus-within {
|
|
||||||
outline: 2px solid ${theme.palette.secondary.main};
|
|
||||||
outline-offset: 1px;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HexWrapper = styled.div`
|
const HexWrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
& input {
|
& input {
|
||||||
min-width: 0px;
|
min-width: 0px;
|
||||||
@@ -277,7 +259,7 @@ const Swatch = styled.div<{ $color: string }>`
|
|||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
${({ $color }): string => {
|
${({ $color }): string => {
|
||||||
if ($color.toUpperCase() === "#FFFFFF") {
|
if ($color.toUpperCase() === "#FFFFFF") {
|
||||||
return `border: 1px solid ${theme.palette.grey["300"]};`;
|
return `border: 1px solid ${theme.palette.grey["600"]};`;
|
||||||
}
|
}
|
||||||
return `border: 1px solid ${$color};`;
|
return `border: 1px solid ${$color};`;
|
||||||
}}
|
}}
|
||||||
@@ -291,8 +273,7 @@ const ColorPickerInput = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 8px;
|
margin-top: 15px;
|
||||||
gap: 8px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default ColorPicker;
|
export default ColorPicker;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export const TOOLBAR_HEIGHT = 48;
|
export const TOOLBAR_HEIGH = 48;
|
||||||
export const FORMULA_BAR_HEIGHT = 40;
|
export const FORMULA_BAR_HEIGH = 40;
|
||||||
export const NAVIGATION_HEIGHT = 40;
|
export const NAVIGATION_HEIGH = 40;
|
||||||
|
|||||||
@@ -7,16 +7,6 @@ import {
|
|||||||
} from "@ironcalc/wasm";
|
} from "@ironcalc/wasm";
|
||||||
import type { ActiveRange } from "../workbookState";
|
import type { ActiveRange } from "../workbookState";
|
||||||
|
|
||||||
function sliceString(
|
|
||||||
text: string,
|
|
||||||
startScalar: number,
|
|
||||||
endScalar: number,
|
|
||||||
): string {
|
|
||||||
const scalarValues = Array.from(text);
|
|
||||||
const sliced = scalarValues.slice(startScalar, endScalar);
|
|
||||||
return sliced.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tokenIsReferenceType(token: TokenType): token is Reference {
|
export function tokenIsReferenceType(token: TokenType): token is Reference {
|
||||||
return typeof token === "object" && "Reference" in token;
|
return typeof token === "object" && "Reference" in token;
|
||||||
}
|
}
|
||||||
@@ -137,7 +127,7 @@ function getFormulaHTML(
|
|||||||
}
|
}
|
||||||
html.push(
|
html.push(
|
||||||
<span key={index} style={{ color }}>
|
<span key={index} style={{ color }}>
|
||||||
{sliceString(formula, start, end)}
|
{formula.slice(start, end)}
|
||||||
</span>,
|
</span>,
|
||||||
);
|
);
|
||||||
activeRanges.push({
|
activeRanges.push({
|
||||||
@@ -172,7 +162,7 @@ function getFormulaHTML(
|
|||||||
}
|
}
|
||||||
html.push(
|
html.push(
|
||||||
<span key={index} style={{ color }}>
|
<span key={index} style={{ color }}>
|
||||||
{sliceString(formula, start, end)}
|
{formula.slice(start, end)}
|
||||||
</span>,
|
</span>,
|
||||||
);
|
);
|
||||||
colorCount += 1;
|
colorCount += 1;
|
||||||
@@ -186,7 +176,7 @@ function getFormulaHTML(
|
|||||||
color,
|
color,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
html.push(<span key={index}>{sliceString(formula, start, end)}</span>);
|
html.push(<span key={index}>{formula.slice(start, end)}</span>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html = [<span key="equals">=</span>].concat(html);
|
html = [<span key="equals">=</span>].concat(html);
|
||||||
|
|||||||
@@ -34,18 +34,11 @@ const FormatMenu = (properties: FormatMenuProps) => {
|
|||||||
>
|
>
|
||||||
{properties.children}
|
{properties.children}
|
||||||
</ChildrenWrapper>
|
</ChildrenWrapper>
|
||||||
<StyledMenu
|
<Menu
|
||||||
open={isMenuOpen}
|
open={isMenuOpen}
|
||||||
onClose={(): void => setMenuOpen(false)}
|
onClose={(): void => setMenuOpen(false)}
|
||||||
anchorEl={anchorElement.current}
|
anchorEl={anchorElement.current}
|
||||||
anchorOrigin={{
|
anchorOrigin={properties.anchorOrigin}
|
||||||
vertical: "bottom",
|
|
||||||
horizontal: "left",
|
|
||||||
}}
|
|
||||||
transformOrigin={{
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "left",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<MenuItemWrapper onClick={(): void => onSelect(NumberFormats.AUTO)}>
|
<MenuItemWrapper onClick={(): void => onSelect(NumberFormats.AUTO)}>
|
||||||
<MenuItemText>{t("toolbar.format_menu.auto")}</MenuItemText>
|
<MenuItemText>{t("toolbar.format_menu.auto")}</MenuItemText>
|
||||||
@@ -114,7 +107,7 @@ const FormatMenu = (properties: FormatMenuProps) => {
|
|||||||
<MenuItemWrapper onClick={(): void => setPickerOpen(true)}>
|
<MenuItemWrapper onClick={(): void => setPickerOpen(true)}>
|
||||||
<MenuItemText>{t("toolbar.format_menu.custom")}</MenuItemText>
|
<MenuItemText>{t("toolbar.format_menu.custom")}</MenuItemText>
|
||||||
</MenuItemWrapper>
|
</MenuItemWrapper>
|
||||||
</StyledMenu>
|
</Menu>
|
||||||
<FormatPicker
|
<FormatPicker
|
||||||
numFmt={properties.numFmt}
|
numFmt={properties.numFmt}
|
||||||
onChange={onSelect}
|
onChange={onSelect}
|
||||||
@@ -126,40 +119,18 @@ const FormatMenu = (properties: FormatMenuProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledMenu = styled(Menu)`
|
|
||||||
& .MuiPaper-root {
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 4px 0px;
|
|
||||||
margin-left: -4px; // Starting with a small offset
|
|
||||||
}
|
|
||||||
& .MuiList-root {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const MenuItemWrapper = styled(MenuItem)`
|
const MenuItemWrapper = styled(MenuItem)`
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
width: calc(100% - 8px);
|
width: 100%;
|
||||||
min-width: 172px;
|
|
||||||
margin: 0px 4px;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 8px;
|
|
||||||
height: 32px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ChildrenWrapper = styled("div")`
|
const ChildrenWrapper = styled("div")`
|
||||||
display: flex;
|
display: flex;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const MenuDivider = styled("div")`
|
const MenuDivider = styled("div")``;
|
||||||
width: 100%;
|
|
||||||
margin: auto;
|
|
||||||
margin-top: 4px;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
border-top: 1px solid #eeeeee;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const MenuItemText = styled("div")`
|
const MenuItemText = styled("div")`
|
||||||
color: #000;
|
color: #000;
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import styled from "@emotion/styled";
|
import {
|
||||||
import { Dialog, TextField } from "@mui/material";
|
Button,
|
||||||
import { Check } from "lucide-react";
|
Dialog,
|
||||||
|
DialogActions,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
|
TextField,
|
||||||
|
} from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { theme } from "../theme";
|
|
||||||
|
|
||||||
type FormatPickerProps = {
|
type FormatPickerProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -18,53 +22,17 @@ const FormatPicker = (properties: FormatPickerProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [formatCode, setFormatCode] = useState(properties.numFmt);
|
const [formatCode, setFormatCode] = useState(properties.numFmt);
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
properties.onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSubmit = (format_code: string): void => {
|
const onSubmit = (format_code: string): void => {
|
||||||
properties.onChange(format_code);
|
properties.onChange(format_code);
|
||||||
properties.onClose();
|
properties.onClose();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog open={properties.open} onClose={properties.onClose}>
|
||||||
open={properties.open}
|
<DialogTitle>{t("num_fmt.title")}</DialogTitle>
|
||||||
onClose={properties.onClose}
|
<DialogContent dividers>
|
||||||
PaperProps={{
|
<TextField
|
||||||
style: { minWidth: "280px" },
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<StyledDialogTitle>
|
|
||||||
{t("num_fmt.title")}
|
|
||||||
<Cross onClick={handleClose} onKeyDown={() => {}}>
|
|
||||||
<svg
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
fill="none"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<title>Close</title>
|
|
||||||
<path
|
|
||||||
d="M12 4.5L4 12.5"
|
|
||||||
stroke="#333333"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M4 4.5L12 12.5"
|
|
||||||
stroke="#333333"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</Cross>
|
|
||||||
</StyledDialogTitle>
|
|
||||||
|
|
||||||
<StyledDialogContent>
|
|
||||||
<StyledTextField
|
|
||||||
autoFocus
|
|
||||||
defaultValue={properties.numFmt}
|
defaultValue={properties.numFmt}
|
||||||
|
label={t("num_fmt.label")}
|
||||||
name="format_code"
|
name="format_code"
|
||||||
onChange={(event) => setFormatCode(event.target.value)}
|
onChange={(event) => setFormatCode(event.target.value)}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
@@ -72,94 +40,15 @@ const FormatPicker = (properties: FormatPickerProps) => {
|
|||||||
}}
|
}}
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
onClick={(event) => event.stopPropagation()}
|
onClick={(event) => event.stopPropagation()}
|
||||||
onFocus={(event) => event.target.select()}
|
|
||||||
/>
|
/>
|
||||||
</StyledDialogContent>
|
</DialogContent>
|
||||||
<DialogFooter>
|
<DialogActions>
|
||||||
<StyledButton onClick={() => onSubmit(formatCode)}>
|
<Button onClick={() => onSubmit(formatCode)}>
|
||||||
<Check
|
|
||||||
style={{ width: "16px", height: "16px", marginRight: "8px" }}
|
|
||||||
/>
|
|
||||||
{t("num_fmt.save")}
|
{t("num_fmt.save")}
|
||||||
</StyledButton>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledDialogTitle = styled("div")`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 44px;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: Inter;
|
|
||||||
padding: 0px 12px;
|
|
||||||
justify-content: space-between;
|
|
||||||
border-bottom: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Cross = styled("div")`
|
|
||||||
&:hover {
|
|
||||||
background-color: ${theme.palette.grey["100"]};
|
|
||||||
}
|
|
||||||
display: flex;
|
|
||||||
border-radius: 4px;
|
|
||||||
height: 24px;
|
|
||||||
width: 24px;
|
|
||||||
cursor: pointer;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledDialogContent = styled("div")`
|
|
||||||
font-size: 12px;
|
|
||||||
margin: 12px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledTextField = styled(TextField)`
|
|
||||||
width: 100%;
|
|
||||||
min-width: 320px;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow: hidden;
|
|
||||||
& .MuiInputBase-input {
|
|
||||||
font-size: 14px;
|
|
||||||
padding: 10px;
|
|
||||||
border: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
border-radius: 4px;
|
|
||||||
color: ${theme.palette.common.black};
|
|
||||||
background-color: ${theme.palette.common.white};
|
|
||||||
}
|
|
||||||
&:hover .MuiInputBase-input {
|
|
||||||
border: 1px solid ${theme.palette.grey["500"]};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const DialogFooter = styled("div")`
|
|
||||||
color: #757575;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
border-top: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
font-family: Inter;
|
|
||||||
justify-content: flex-end;
|
|
||||||
padding: 12px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledButton = styled("div")`
|
|
||||||
cursor: pointer;
|
|
||||||
color: #ffffff;
|
|
||||||
background: #f2994a;
|
|
||||||
padding: 0px 10px;
|
|
||||||
height: 36px;
|
|
||||||
line-height: 36px;
|
|
||||||
border-radius: 4px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-family: "Inter";
|
|
||||||
font-size: 14px;
|
|
||||||
&:hover {
|
|
||||||
background: #d68742;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default FormatPicker;
|
export default FormatPicker;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
COLUMN_WIDTH_SCALE,
|
COLUMN_WIDTH_SCALE,
|
||||||
ROW_HEIGH_SCALE,
|
ROW_HEIGH_SCALE,
|
||||||
} from "./WorksheetCanvas/constants";
|
} from "./WorksheetCanvas/constants";
|
||||||
import { FORMULA_BAR_HEIGHT } from "./constants";
|
import { FORMULA_BAR_HEIGH } from "./constants";
|
||||||
import Editor from "./editor/editor";
|
import Editor from "./editor/editor";
|
||||||
import type { WorkbookState } from "./workbookState";
|
import type { WorkbookState } from "./workbookState";
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ const Container = styled("div")`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
background: ${(properties): string =>
|
background: ${(properties): string =>
|
||||||
properties.theme.palette.background.default};
|
properties.theme.palette.background.default};
|
||||||
height: ${FORMULA_BAR_HEIGHT}px;
|
height: ${FORMULA_BAR_HEIGH}px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const AddressContainer = styled("div")`
|
const AddressContainer = styled("div")`
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
import { Dialog, TextField, styled } from "@mui/material";
|
import {
|
||||||
|
Button,
|
||||||
|
Dialog,
|
||||||
|
DialogActions,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
|
TextField,
|
||||||
|
styled,
|
||||||
|
} from "@mui/material";
|
||||||
import Menu from "@mui/material/Menu";
|
import Menu from "@mui/material/Menu";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import { Check } from "lucide-react";
|
import { Check } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { theme } from "../../theme";
|
|
||||||
import type { SheetOptions } from "./types";
|
import type { SheetOptions } from "./types";
|
||||||
|
|
||||||
function isWhiteColor(color: string): boolean {
|
function isWhiteColor(color: string): boolean {
|
||||||
@@ -21,65 +28,32 @@ interface SheetRenameDialogProps {
|
|||||||
export const SheetRenameDialog = (properties: SheetRenameDialogProps) => {
|
export const SheetRenameDialog = (properties: SheetRenameDialogProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [name, setName] = useState(properties.defaultName);
|
const [name, setName] = useState(properties.defaultName);
|
||||||
const handleClose = () => {
|
|
||||||
properties.close();
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={properties.isOpen} onClose={properties.close}>
|
<Dialog open={properties.isOpen} onClose={properties.close}>
|
||||||
<StyledDialogTitle>
|
<DialogTitle>{t("sheet_rename.title")}</DialogTitle>
|
||||||
{t("sheet_rename.title")}
|
<DialogContent dividers>
|
||||||
<Cross onClick={handleClose} onKeyDown={() => {}}>
|
<TextField
|
||||||
<svg
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
fill="none"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<title>Close</title>
|
|
||||||
<path
|
|
||||||
d="M12 4.5L4 12.5"
|
|
||||||
stroke="#333333"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M4 4.5L12 12.5"
|
|
||||||
stroke="#333333"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</Cross>
|
|
||||||
</StyledDialogTitle>
|
|
||||||
<StyledDialogContent>
|
|
||||||
<StyledTextField
|
|
||||||
autoFocus
|
|
||||||
defaultValue={properties.defaultName}
|
defaultValue={properties.defaultName}
|
||||||
|
label={t("sheet_rename.label")}
|
||||||
onClick={(event) => event.stopPropagation()}
|
onClick={(event) => event.stopPropagation()}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (event.key === "Enter") {
|
|
||||||
properties.onNameChanged(name);
|
|
||||||
properties.close();
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setName(event.target.value);
|
setName(event.target.value);
|
||||||
}}
|
}}
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
onPaste={(event) => event.stopPropagation()}
|
|
||||||
/>
|
/>
|
||||||
</StyledDialogContent>
|
</DialogContent>
|
||||||
<DialogFooter>
|
<DialogActions>
|
||||||
<StyledButton
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
properties.onNameChanged(name);
|
properties.onNameChanged(name);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("sheet_rename.rename")}
|
{t("sheet_rename.rename")}
|
||||||
</StyledButton>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -172,78 +146,4 @@ const ItemName = styled("div")`
|
|||||||
color: #333;
|
color: #333;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledDialogTitle = styled("div")`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 44px;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: Inter;
|
|
||||||
padding: 0px 12px;
|
|
||||||
justify-content: space-between;
|
|
||||||
border-bottom: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Cross = styled("div")`
|
|
||||||
&:hover {
|
|
||||||
background-color: ${theme.palette.grey["100"]};
|
|
||||||
}
|
|
||||||
display: flex;
|
|
||||||
border-radius: 4px;
|
|
||||||
height: 24px;
|
|
||||||
width: 24px;
|
|
||||||
cursor: pointer;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledDialogContent = styled("div")`
|
|
||||||
font-size: 12px;
|
|
||||||
margin: 12px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledTextField = styled(TextField)`
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow: hidden;
|
|
||||||
& .MuiInputBase-input {
|
|
||||||
font-size: 14px;
|
|
||||||
padding: 10px;
|
|
||||||
border: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
border-radius: 4px;
|
|
||||||
color: ${theme.palette.common.black};
|
|
||||||
background-color: ${theme.palette.common.white};
|
|
||||||
}
|
|
||||||
&:hover .MuiInputBase-input {
|
|
||||||
border: 1px solid ${theme.palette.grey["500"]};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const DialogFooter = styled("div")`
|
|
||||||
color: #757575;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
border-top: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
font-family: Inter;
|
|
||||||
justify-content: flex-end;
|
|
||||||
padding: 12px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledButton = styled("div")`
|
|
||||||
cursor: pointer;
|
|
||||||
color: #ffffff;
|
|
||||||
background: #f2994a;
|
|
||||||
padding: 0px 10px;
|
|
||||||
height: 36px;
|
|
||||||
line-height: 36px;
|
|
||||||
border-radius: 4px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-family: "Inter";
|
|
||||||
font-size: 14px;
|
|
||||||
&:hover {
|
|
||||||
background: #d68742;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default SheetListMenu;
|
export default SheetListMenu;
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import { styled } from "@mui/material";
|
|||||||
import { Menu, Plus } from "lucide-react";
|
import { Menu, Plus } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { theme } from "../../theme";
|
import { NAVIGATION_HEIGH } from "../constants";
|
||||||
import { NAVIGATION_HEIGHT } from "../constants";
|
|
||||||
import { StyledButton } from "../toolbar";
|
import { StyledButton } from "../toolbar";
|
||||||
import type { WorkbookState } from "../workbookState";
|
import type { WorkbookState } from "../workbookState";
|
||||||
import SheetListMenu from "./menus";
|
import SheetListMenu from "./menus";
|
||||||
@@ -97,19 +96,17 @@ const Container = styled("div")`
|
|||||||
left: 0px;
|
left: 0px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
display: flex;
|
display: flex;
|
||||||
height: ${NAVIGATION_HEIGHT}px;
|
height: ${NAVIGATION_HEIGH}px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
font-family: Inter;
|
font-family: Inter;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-top: 1px solid #e0e0e0;
|
border-top: 1px solid #E0E0E0;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Sheets = styled("div")`
|
const Sheets = styled("div")`
|
||||||
flex-grow: 2;
|
flex-grow: 2;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
overflow-x: auto;
|
|
||||||
scrollbar-width: none;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const SheetInner = styled("div")`
|
const SheetInner = styled("div")`
|
||||||
@@ -117,20 +114,10 @@ const SheetInner = styled("div")`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const Advert = styled("a")`
|
const Advert = styled("a")`
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
color: #f2994a;
|
color: #f2994a;
|
||||||
padding: 0px 12px;
|
margin-right: 12px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-left: 1px solid ${theme.palette.grey["300"]};
|
|
||||||
transition: color 0.2s ease-in-out;
|
|
||||||
&:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
@media (max-width: 769px) {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default Navigation;
|
export default Navigation;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import {
|
|||||||
import { theme } from "../theme";
|
import { theme } from "../theme";
|
||||||
import BorderPicker from "./borderPicker";
|
import BorderPicker from "./borderPicker";
|
||||||
import ColorPicker from "./colorPicker";
|
import ColorPicker from "./colorPicker";
|
||||||
import { TOOLBAR_HEIGHT } from "./constants";
|
import { TOOLBAR_HEIGH } from "./constants";
|
||||||
import FormatMenu from "./formatMenu";
|
import FormatMenu from "./formatMenu";
|
||||||
import {
|
import {
|
||||||
NumberFormats,
|
NumberFormats,
|
||||||
@@ -251,16 +251,6 @@ function Toolbar(properties: ToolbarProperties) {
|
|||||||
>
|
>
|
||||||
<PaintBucket />
|
<PaintBucket />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
<StyledButton
|
|
||||||
type="button"
|
|
||||||
$pressed={false}
|
|
||||||
onClick={() => setBorderPickerOpen(true)}
|
|
||||||
ref={borderButton}
|
|
||||||
disabled={!canEdit}
|
|
||||||
title={t("toolbar.borders.title")}
|
|
||||||
>
|
|
||||||
<Grid2X2 />
|
|
||||||
</StyledButton>
|
|
||||||
<Divider />
|
<Divider />
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type="button"
|
type="button"
|
||||||
@@ -328,7 +318,17 @@ function Toolbar(properties: ToolbarProperties) {
|
|||||||
>
|
>
|
||||||
<ArrowDownToLine />
|
<ArrowDownToLine />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
<Divider />
|
||||||
|
<StyledButton
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
onClick={() => setBorderPickerOpen(true)}
|
||||||
|
ref={borderButton}
|
||||||
|
disabled={!canEdit}
|
||||||
|
title={t("toolbar.borders.title")}
|
||||||
|
>
|
||||||
|
<Grid2X2 />
|
||||||
|
</StyledButton>
|
||||||
<Divider />
|
<Divider />
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type="button"
|
type="button"
|
||||||
@@ -385,8 +385,8 @@ const ToolbarContainer = styled("div")`
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: ${({ theme }) => theme.palette.background.paper};
|
background: ${({ theme }) => theme.palette.background.paper};
|
||||||
height: ${TOOLBAR_HEIGHT}px;
|
height: ${TOOLBAR_HEIGH}px;
|
||||||
line-height: ${TOOLBAR_HEIGHT}px;
|
line-height: ${TOOLBAR_HEIGH}px;
|
||||||
border-bottom: 1px solid ${({ theme }) => theme.palette.grey["300"]};
|
border-bottom: 1px solid ${({ theme }) => theme.palette.grey["300"]};
|
||||||
font-family: Inter;
|
font-family: Inter;
|
||||||
border-radius: 4px 4px 0px 0px;
|
border-radius: 4px 4px 0px 0px;
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
);
|
);
|
||||||
setRedrawId((id) => id + 1);
|
setRedrawId((id) => id + 1);
|
||||||
}}
|
}}
|
||||||
fillColor={style.fill.fg_color || "#FFFFFF"}
|
fillColor={style.fill.fg_color || "#FFF"}
|
||||||
fontColor={style.font.color}
|
fontColor={style.font.color}
|
||||||
bold={style.font.b}
|
bold={style.font.b}
|
||||||
underline={style.font.u}
|
underline={style.font.u}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import {
|
|||||||
} from "./WorksheetCanvas/constants";
|
} from "./WorksheetCanvas/constants";
|
||||||
import WorksheetCanvas from "./WorksheetCanvas/worksheetCanvas";
|
import WorksheetCanvas from "./WorksheetCanvas/worksheetCanvas";
|
||||||
import {
|
import {
|
||||||
FORMULA_BAR_HEIGHT,
|
FORMULA_BAR_HEIGH,
|
||||||
NAVIGATION_HEIGHT,
|
NAVIGATION_HEIGH,
|
||||||
TOOLBAR_HEIGHT,
|
TOOLBAR_HEIGH,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import Editor from "./editor/editor";
|
import Editor from "./editor/editor";
|
||||||
import type { Cell } from "./types";
|
import type { Cell } from "./types";
|
||||||
@@ -104,16 +104,10 @@ function Worksheet(props: {
|
|||||||
editor: editor,
|
editor: editor,
|
||||||
},
|
},
|
||||||
onColumnWidthChanges(sheet, column, width) {
|
onColumnWidthChanges(sheet, column, width) {
|
||||||
if (width < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
model.setColumnWidth(sheet, column, width);
|
model.setColumnWidth(sheet, column, width);
|
||||||
worksheetCanvas.current?.renderSheet();
|
worksheetCanvas.current?.renderSheet();
|
||||||
},
|
},
|
||||||
onRowHeightChanges(sheet, row, height) {
|
onRowHeightChanges(sheet, row, height) {
|
||||||
if (height < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
model.setRowHeight(sheet, row, height);
|
model.setRowHeight(sheet, row, height);
|
||||||
worksheetCanvas.current?.renderSheet();
|
worksheetCanvas.current?.renderSheet();
|
||||||
},
|
},
|
||||||
@@ -439,10 +433,10 @@ const SheetContainer = styled("div")`
|
|||||||
const Wrapper = styled("div")({
|
const Wrapper = styled("div")({
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
overflow: "scroll",
|
overflow: "scroll",
|
||||||
top: TOOLBAR_HEIGHT + FORMULA_BAR_HEIGHT + 1,
|
top: TOOLBAR_HEIGH + FORMULA_BAR_HEIGH + 1,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: NAVIGATION_HEIGHT + 1,
|
bottom: NAVIGATION_HEIGH + 1,
|
||||||
overscrollBehavior: "none",
|
overscrollBehavior: "none",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -246,8 +246,18 @@ pub(crate) fn get_worksheet_xml(
|
|||||||
}
|
}
|
||||||
let sheet_data = sheet_data_str.join("");
|
let sheet_data = sheet_data_str.join("");
|
||||||
|
|
||||||
for merge_cell_ref in &worksheet.merge_cells {
|
for merged_cells_ref in &worksheet.merged_cells_list {
|
||||||
merged_cells_str.push(format!("<mergeCell ref=\"{merge_cell_ref}\"/>"))
|
let merged_cells_range_str_ref: String = match merged_cells_ref.get_merged_cells_str_ref() {
|
||||||
|
Ok(merged_cells_ref) => merged_cells_ref,
|
||||||
|
Err(err) => {
|
||||||
|
// ATTENTION : This should not happen. There should not be error while exporting
|
||||||
|
// already imported/created Mergedcells structure
|
||||||
|
// Currently, this function does not return any error. so logging the error and skipping this errored one
|
||||||
|
println!("{}", err);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
merged_cells_str.push(format!("<mergeCell ref=\"{merged_cells_range_str_ref}\"/>"))
|
||||||
}
|
}
|
||||||
let merged_cells_count = merged_cells_str.len();
|
let merged_cells_count = merged_cells_str.len();
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ironcalc_base::{
|
|||||||
utils::{column_to_number, parse_reference_a1},
|
utils::{column_to_number, parse_reference_a1},
|
||||||
},
|
},
|
||||||
types::{
|
types::{
|
||||||
Cell, Col, Comment, DefinedName, Row, SheetData, SheetState, Table, Worksheet,
|
Cell, Col, Comment, DefinedName, MergedCells, Row, SheetData, SheetState, Table, Worksheet,
|
||||||
WorksheetView,
|
WorksheetView,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -148,12 +148,12 @@ fn load_columns(ws: Node) -> Result<Vec<Col>, XlsxError> {
|
|||||||
Ok(cols)
|
Ok(cols)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_merge_cells(ws: Node) -> Result<Vec<String>, XlsxError> {
|
fn load_merge_cells_nodes(ws: Node) -> Result<Vec<MergedCells>, XlsxError> {
|
||||||
// 18.3.1.55 Merge Cells
|
// 18.3.1.55 Merge Cells
|
||||||
// <mergeCells count="1">
|
// <mergeCells count="1">
|
||||||
// <mergeCell ref="K7:L10"/>
|
// <mergeCell ref="K7:L10"/>
|
||||||
// </mergeCells>
|
// </mergeCells>
|
||||||
let mut merge_cells = Vec::new();
|
let mut merged_cells_list: Vec<MergedCells> = Vec::new();
|
||||||
let merge_cells_nodes = ws
|
let merge_cells_nodes = ws
|
||||||
.children()
|
.children()
|
||||||
.filter(|n| n.has_tag_name("mergeCells"))
|
.filter(|n| n.has_tag_name("mergeCells"))
|
||||||
@@ -161,10 +161,18 @@ fn load_merge_cells(ws: Node) -> Result<Vec<String>, XlsxError> {
|
|||||||
if merge_cells_nodes.len() == 1 {
|
if merge_cells_nodes.len() == 1 {
|
||||||
for merge_cell in merge_cells_nodes[0].children() {
|
for merge_cell in merge_cells_nodes[0].children() {
|
||||||
let reference = get_attribute(&merge_cell, "ref")?.to_string();
|
let reference = get_attribute(&merge_cell, "ref")?.to_string();
|
||||||
merge_cells.push(reference);
|
match parse_range(&reference) {
|
||||||
|
Ok(parsed_merge_cell_range) => {
|
||||||
|
let merge_cell_node = MergedCells::new(parsed_merge_cell_range);
|
||||||
|
merged_cells_list.push(merge_cell_node);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("encountered error while parsing merge cell ref : {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(merge_cells)
|
Ok(merged_cells_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_sheet_color(ws: Node) -> Result<Option<String>, XlsxError> {
|
fn load_sheet_color(ws: Node) -> Result<Option<String>, XlsxError> {
|
||||||
@@ -943,7 +951,7 @@ pub(super) fn load_sheet<R: Read + std::io::Seek>(
|
|||||||
sheet_data.insert(row_index, data_row);
|
sheet_data.insert(row_index, data_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
let merge_cells = load_merge_cells(ws)?;
|
let merge_cells_nodes = load_merge_cells_nodes(ws)?;
|
||||||
|
|
||||||
// Conditional Formatting
|
// Conditional Formatting
|
||||||
// <conditionalFormatting sqref="B1:B9">
|
// <conditionalFormatting sqref="B1:B9">
|
||||||
@@ -982,7 +990,7 @@ pub(super) fn load_sheet<R: Read + std::io::Seek>(
|
|||||||
sheet_id,
|
sheet_id,
|
||||||
state: state.to_owned(),
|
state: state.to_owned(),
|
||||||
color,
|
color,
|
||||||
merge_cells,
|
merged_cells_list: merge_cells_nodes,
|
||||||
comments: settings.comments,
|
comments: settings.comments,
|
||||||
frozen_rows: sheet_view.frozen_rows,
|
frozen_rows: sheet_view.frozen_rows,
|
||||||
frozen_columns: sheet_view.frozen_columns,
|
frozen_columns: sheet_view.frozen_columns,
|
||||||
|
|||||||
BIN
xlsx/tests/Merged_cells.xlsx
Normal file
BIN
xlsx/tests/Merged_cells.xlsx
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -406,7 +406,7 @@ fn test_exporting_merged_cells() {
|
|||||||
.worksheets
|
.worksheets
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.merge_cells
|
.merged_cells_list
|
||||||
.clone();
|
.clone();
|
||||||
// exporting and saving it in another xlsx
|
// exporting and saving it in another xlsx
|
||||||
model.evaluate();
|
model.evaluate();
|
||||||
@@ -423,7 +423,7 @@ fn test_exporting_merged_cells() {
|
|||||||
.worksheets
|
.worksheets
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.merge_cells
|
.merged_cells_list
|
||||||
.clone();
|
.clone();
|
||||||
assert_eq!(expected_merge_cell_ref, *got_merge_cell_ref);
|
assert_eq!(expected_merge_cell_ref, *got_merge_cell_ref);
|
||||||
fs::remove_file(temp_file_name).unwrap();
|
fs::remove_file(temp_file_name).unwrap();
|
||||||
@@ -437,7 +437,7 @@ fn test_exporting_merged_cells() {
|
|||||||
.worksheets
|
.worksheets
|
||||||
.get_mut(0)
|
.get_mut(0)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.merge_cells
|
.merged_cells_list
|
||||||
.clear();
|
.clear();
|
||||||
|
|
||||||
save_to_xlsx(&temp_model, temp_file_name).unwrap();
|
save_to_xlsx(&temp_model, temp_file_name).unwrap();
|
||||||
@@ -447,7 +447,7 @@ fn test_exporting_merged_cells() {
|
|||||||
.worksheets
|
.worksheets
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.merge_cells
|
.merged_cells_list
|
||||||
.len();
|
.len();
|
||||||
assert!(*got_merge_cell_ref_cnt == 0);
|
assert!(*got_merge_cell_ref_cnt == 0);
|
||||||
}
|
}
|
||||||
@@ -494,3 +494,73 @@ fn test_documentation_xlsx() {
|
|||||||
}
|
}
|
||||||
fs::remove_dir_all(&dir).unwrap();
|
fs::remove_dir_all(&dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_merge_cell_import_export_behaviors() {
|
||||||
|
// loading the xlsx file containing merged cells
|
||||||
|
let example_file_name = "tests/Merged_cells.xlsx";
|
||||||
|
let mut model = load_from_xlsx(example_file_name, "en", "UTC").unwrap();
|
||||||
|
|
||||||
|
// Case1 : To check whether Merge cells structures got imported properly or not
|
||||||
|
let imported_merge_cell_vec = model.workbook.worksheet(0).unwrap().get_merged_cells_list();
|
||||||
|
|
||||||
|
assert_eq!(imported_merge_cell_vec.len(), 5);
|
||||||
|
let range_refs_of_merge_cell: Vec<String> = imported_merge_cell_vec
|
||||||
|
.iter()
|
||||||
|
.map(|cell| cell.get_merged_cells_str_ref().unwrap())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(
|
||||||
|
range_refs_of_merge_cell,
|
||||||
|
[
|
||||||
|
"C1:D3".to_string(),
|
||||||
|
"A1:B4".to_string(),
|
||||||
|
"G1:H7".to_string(),
|
||||||
|
"D8:E9".to_string(),
|
||||||
|
"D4:F6".to_string()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create one More Merge cell which Overlaps with 3 More
|
||||||
|
model.merge_cells(0, "A1:D5").unwrap();
|
||||||
|
model
|
||||||
|
.set_user_input(0, 1, 1, "New overlapped Merge cell".to_string())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut style = model.get_style_for_cell(0, 1, 1).unwrap();
|
||||||
|
style.font.b = true;
|
||||||
|
assert_eq!(
|
||||||
|
model.workbook.styles.create_named_style("bold", &style),
|
||||||
|
Ok(())
|
||||||
|
);
|
||||||
|
|
||||||
|
model.set_cell_style_by_name(0, 1, 1, "bold").unwrap();
|
||||||
|
|
||||||
|
// Lets export to different Excell
|
||||||
|
let exported_merge_cell_xlsx = "temporary_exported_mergecells.xlsx";
|
||||||
|
save_to_xlsx(&model, exported_merge_cell_xlsx).unwrap();
|
||||||
|
|
||||||
|
{
|
||||||
|
let temp_model = load_from_xlsx(exported_merge_cell_xlsx, "en", "UTC").unwrap();
|
||||||
|
// Loading the exported sheet back and verifying whether it got exported properly or not
|
||||||
|
let imported_merge_cell_vec = temp_model
|
||||||
|
.workbook
|
||||||
|
.worksheet(0)
|
||||||
|
.unwrap()
|
||||||
|
.get_merged_cells_list();
|
||||||
|
|
||||||
|
assert_eq!(imported_merge_cell_vec.len(), 3);
|
||||||
|
let range_refs_of_merge_cell: Vec<String> = imported_merge_cell_vec
|
||||||
|
.iter()
|
||||||
|
.map(|cell| cell.get_merged_cells_str_ref().unwrap())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(
|
||||||
|
range_refs_of_merge_cell,
|
||||||
|
[
|
||||||
|
"G1:H7".to_string(),
|
||||||
|
"D8:E9".to_string(),
|
||||||
|
"A1:D5".to_string()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fs::remove_file(exported_merge_cell_xlsx).unwrap();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user