Compare commits
1 Commits
hackaton
...
feature/ni
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48727b1b39 |
4
.github/workflows/pypi.yml
vendored
4
.github/workflows/pypi.yml
vendored
@@ -117,7 +117,7 @@ jobs:
|
|||||||
MATURIN_REPOSITORY_URL: "https://test.pypi.org/legacy/"
|
MATURIN_REPOSITORY_URL: "https://test.pypi.org/legacy/"
|
||||||
with:
|
with:
|
||||||
command: upload
|
command: upload
|
||||||
args: "--skip-existing **/*.whl **/*.tar.gz"
|
args: "--skip-existing **/*.whl"
|
||||||
working-directory: bindings/python
|
working-directory: bindings/python
|
||||||
|
|
||||||
publish-pypi:
|
publish-pypi:
|
||||||
@@ -137,5 +137,5 @@ jobs:
|
|||||||
MATURIN_REPOSITORY_URL: "https://upload.pypi.org/legacy/"
|
MATURIN_REPOSITORY_URL: "https://upload.pypi.org/legacy/"
|
||||||
with:
|
with:
|
||||||
command: upload
|
command: upload
|
||||||
args: "--skip-existing **/*.whl **/*.tar.gz"
|
args: "--skip-existing **/*.whl"
|
||||||
working-directory: bindings/python
|
working-directory: bindings/python
|
||||||
|
|||||||
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -721,10 +721,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3"
|
name = "pyo3"
|
||||||
version = "0.25.0"
|
version = "0.23.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f239d656363bcee73afef85277f1b281e8ac6212a1d42aa90e55b90ed43c47a4"
|
checksum = "57fe09249128b3173d092de9523eaa75136bf7ba85e0d69eca241c7939c933cc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
"indoc",
|
"indoc",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
@@ -738,9 +739,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-build-config"
|
name = "pyo3-build-config"
|
||||||
version = "0.25.0"
|
version = "0.23.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "755ea671a1c34044fa165247aaf6f419ca39caa6003aee791a0df2713d8f1b6d"
|
checksum = "1cd3927b5a78757a0d71aa9dff669f903b1eb64b54142a9bd9f757f8fde65fd7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
@@ -748,9 +749,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-ffi"
|
name = "pyo3-ffi"
|
||||||
version = "0.25.0"
|
version = "0.23.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc95a2e67091e44791d4ea300ff744be5293f394f1bafd9f78c080814d35956e"
|
checksum = "dab6bb2102bd8f991e7749f130a70d05dd557613e39ed2deeee8e9ca0c4d548d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
@@ -758,9 +759,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros"
|
name = "pyo3-macros"
|
||||||
version = "0.25.0"
|
version = "0.23.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a179641d1b93920829a62f15e87c0ed791b6c8db2271ba0fd7c2686090510214"
|
checksum = "91871864b353fd5ffcb3f91f2f703a22a9797c91b9ab497b1acac7b07ae509c7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"pyo3-macros-backend",
|
"pyo3-macros-backend",
|
||||||
@@ -770,9 +771,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros-backend"
|
name = "pyo3-macros-backend"
|
||||||
version = "0.25.0"
|
version = "0.23.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9dff85ebcaab8c441b0e3f7ae40a6963ecea8a9f5e74f647e33fcf5ec9a1e89e"
|
checksum = "43abc3b80bc20f3facd86cd3c60beed58c3e2aa26213f3cda368de39c60a27e4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -783,9 +784,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyroncalc"
|
name = "pyroncalc"
|
||||||
version = "0.5.6"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitcode",
|
|
||||||
"ironcalc",
|
"ironcalc",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -979,9 +979,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "target-lexicon"
|
name = "target-lexicon"
|
||||||
version = "0.13.2"
|
version = "0.12.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
|
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
@@ -1070,7 +1070,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
version = "0.5.3"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ironcalc_base",
|
"ironcalc_base",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ impl Cell {
|
|||||||
Cell::CellFormulaNumber { s, .. } => *s = style,
|
Cell::CellFormulaNumber { s, .. } => *s = style,
|
||||||
Cell::CellFormulaString { s, .. } => *s = style,
|
Cell::CellFormulaString { s, .. } => *s = style,
|
||||||
Cell::CellFormulaError { s, .. } => *s = style,
|
Cell::CellFormulaError { s, .. } => *s = style,
|
||||||
|
// Should we throw an error here?
|
||||||
|
Cell::Merged { .. } => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +106,8 @@ impl Cell {
|
|||||||
Cell::CellFormulaNumber { s, .. } => *s,
|
Cell::CellFormulaNumber { s, .. } => *s,
|
||||||
Cell::CellFormulaString { s, .. } => *s,
|
Cell::CellFormulaString { s, .. } => *s,
|
||||||
Cell::CellFormulaError { s, .. } => *s,
|
Cell::CellFormulaError { s, .. } => *s,
|
||||||
|
// A merged cell has no style
|
||||||
|
Cell::Merged { .. } => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +123,7 @@ impl Cell {
|
|||||||
Cell::CellFormulaNumber { .. } => CellType::Number,
|
Cell::CellFormulaNumber { .. } => CellType::Number,
|
||||||
Cell::CellFormulaString { .. } => CellType::Text,
|
Cell::CellFormulaString { .. } => CellType::Text,
|
||||||
Cell::CellFormulaError { .. } => CellType::ErrorValue,
|
Cell::CellFormulaError { .. } => CellType::ErrorValue,
|
||||||
|
Cell::Merged { .. } => CellType::Number,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +161,7 @@ impl Cell {
|
|||||||
let v = ei.to_localized_error_string(language);
|
let v = ei.to_localized_error_string(language);
|
||||||
CellValue::String(v)
|
CellValue::String(v)
|
||||||
}
|
}
|
||||||
|
Cell::Merged { .. } => CellValue::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ pub mod mock_time;
|
|||||||
|
|
||||||
pub use model::get_milliseconds_since_epoch;
|
pub use model::get_milliseconds_since_epoch;
|
||||||
pub use model::Model;
|
pub use model::Model;
|
||||||
|
pub use model::CellStructure;
|
||||||
pub use user_model::BorderArea;
|
pub use user_model::BorderArea;
|
||||||
pub use user_model::ClipboardData;
|
pub use user_model::ClipboardData;
|
||||||
pub use user_model::UserModel;
|
pub use user_model::UserModel;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use chrono_tz::Tz;
|
use chrono_tz::Tz;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub use crate::mock_time::get_milliseconds_since_epoch;
|
pub use crate::mock_time::get_milliseconds_since_epoch;
|
||||||
@@ -72,6 +73,27 @@ pub(crate) enum CellState {
|
|||||||
Evaluating,
|
Evaluating,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cell structure indicates if the cell is part of a merged cell or not
|
||||||
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
pub enum CellStructure {
|
||||||
|
/// The cell is not part of a merged cell
|
||||||
|
Simple,
|
||||||
|
/// The cell is part of a merged cell, and teh root cell is (row, column)
|
||||||
|
Merged {
|
||||||
|
/// Row of the root cell
|
||||||
|
row: i32,
|
||||||
|
/// Column of the root cell
|
||||||
|
column: i32,
|
||||||
|
},
|
||||||
|
/// The cell is the root of a merged cell of dimensions (width, height)
|
||||||
|
MergedRoot {
|
||||||
|
/// Width of the merged cell
|
||||||
|
width: i32,
|
||||||
|
/// Height of the merged cell
|
||||||
|
height: i32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
/// A parsed formula for a defined name
|
/// A parsed formula for a defined name
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) enum ParsedDefinedName {
|
pub(crate) enum ParsedDefinedName {
|
||||||
@@ -751,6 +773,7 @@ impl Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Merged { .. } => CalcResult::EmptyCell,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1438,6 +1461,10 @@ impl Model {
|
|||||||
value: String,
|
value: String,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
// 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 cell = self.workbook.worksheet(sheet)?.cell(row, column);
|
||||||
|
if matches!(cell, Some(Cell::Merged { .. })) {
|
||||||
|
return Err("Cannot set value on merged cell".to_string());
|
||||||
|
}
|
||||||
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('\'') {
|
||||||
// First check if it needs quoting
|
// First check if it needs quoting
|
||||||
@@ -2258,6 +2285,91 @@ impl Model {
|
|||||||
pub fn delete_row_style(&mut self, sheet: u32, row: i32) -> Result<(), String> {
|
pub fn delete_row_style(&mut self, sheet: u32, row: i32) -> Result<(), String> {
|
||||||
self.workbook.worksheet_mut(sheet)?.delete_row_style(row)
|
self.workbook.worksheet_mut(sheet)?.delete_row_style(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the geometric structure of a cell
|
||||||
|
pub fn get_cell_structure(
|
||||||
|
&self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
) -> Result<CellStructure, String> {
|
||||||
|
let worksheet = self.workbook.worksheet(sheet)?;
|
||||||
|
worksheet.get_cell_structure(row, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Merges cells
|
||||||
|
pub fn merge_cells(
|
||||||
|
&mut self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let worksheet = self.workbook.worksheet_mut(sheet)?;
|
||||||
|
let sheet_data = &mut worksheet.sheet_data;
|
||||||
|
// First check that it is possible to merge the cells
|
||||||
|
for r in row..(row + height) {
|
||||||
|
for c in column..(column + width) {
|
||||||
|
if let Some(Cell::Merged { .. }) =
|
||||||
|
sheet_data.get(&r).and_then(|row_data| row_data.get(&c))
|
||||||
|
{
|
||||||
|
return Err("Cannot merge cells".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
worksheet
|
||||||
|
.merged_cells
|
||||||
|
.insert((row, column), (width, height));
|
||||||
|
for r in row..(row + height) {
|
||||||
|
for c in column..(column + width) {
|
||||||
|
// We remove everything except the "root" cell:
|
||||||
|
if r == row && c == column {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(row_data) = sheet_data.get_mut(&r) {
|
||||||
|
row_data.remove(&c);
|
||||||
|
row_data.insert(c, Cell::Merged { r: row, c: column });
|
||||||
|
} else {
|
||||||
|
let mut row_data = HashMap::new();
|
||||||
|
row_data.insert(c, Cell::Merged { r: row, c: column });
|
||||||
|
sheet_data.insert(r, row_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unmerges cells
|
||||||
|
pub fn unmerge_cells(&mut self, sheet: u32, row: i32, column: i32) -> Result<(), String> {
|
||||||
|
let s = self.get_cell_style_index(sheet, row, column)?;
|
||||||
|
let worksheet = self.workbook.worksheet_mut(sheet)?;
|
||||||
|
let sheet_data = &mut worksheet.sheet_data;
|
||||||
|
let (width, height) = match worksheet.merged_cells.get(&(row, column)) {
|
||||||
|
Some((w, h)) => (*w, *h),
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
worksheet.merged_cells.remove(&(row, column));
|
||||||
|
for r in row..(row + width) {
|
||||||
|
for c in column..(column + height) {
|
||||||
|
// We remove everything except the "root" cell:
|
||||||
|
if r == row && c == column {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(row_data) = sheet_data.get_mut(&r) {
|
||||||
|
row_data.remove(&c);
|
||||||
|
if s != 0 {
|
||||||
|
row_data.insert(c, Cell::EmptyCell { s });
|
||||||
|
}
|
||||||
|
} else if s != 0 {
|
||||||
|
let mut row_data = HashMap::new();
|
||||||
|
row_data.insert(c, Cell::EmptyCell { s });
|
||||||
|
sheet_data.insert(r, row_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ impl Model {
|
|||||||
rows: vec![],
|
rows: vec![],
|
||||||
comments: vec![],
|
comments: vec![],
|
||||||
dimension: "A1".to_string(),
|
dimension: "A1".to_string(),
|
||||||
merge_cells: vec![],
|
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
shared_formulas: vec![],
|
shared_formulas: vec![],
|
||||||
sheet_data: Default::default(),
|
sheet_data: Default::default(),
|
||||||
|
merged_cells: HashMap::new(),
|
||||||
sheet_id,
|
sheet_id,
|
||||||
state: SheetState::Visible,
|
state: SheetState::Visible,
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
@@ -405,7 +405,6 @@ impl Model {
|
|||||||
},
|
},
|
||||||
tables: HashMap::new(),
|
tables: HashMap::new(),
|
||||||
views,
|
views,
|
||||||
users: Vec::new(),
|
|
||||||
};
|
};
|
||||||
let parsed_formulas = Vec::new();
|
let parsed_formulas = Vec::new();
|
||||||
let worksheets = &workbook.worksheets;
|
let worksheets = &workbook.worksheets;
|
||||||
|
|||||||
@@ -39,14 +39,6 @@ pub struct WorkbookView {
|
|||||||
pub window_height: i64,
|
pub window_height: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct WebUser {
|
|
||||||
pub id: String,
|
|
||||||
pub sheet: u32,
|
|
||||||
pub row: i32,
|
|
||||||
pub column: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An internal representation of an IronCalc Workbook
|
/// An internal representation of an IronCalc Workbook
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
pub struct Workbook {
|
pub struct Workbook {
|
||||||
@@ -59,7 +51,6 @@ pub struct Workbook {
|
|||||||
pub metadata: Metadata,
|
pub metadata: Metadata,
|
||||||
pub tables: HashMap<String, Table>,
|
pub tables: HashMap<String, Table>,
|
||||||
pub views: HashMap<u32, WorkbookView>,
|
pub views: HashMap<u32, WorkbookView>,
|
||||||
pub users: Vec<WebUser>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A defined name. The `sheet_id` is the sheet index in case the name is local
|
/// A defined name. The `sheet_id` is the sheet index in case the name is local
|
||||||
@@ -119,7 +110,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: HashMap<(i32, i32), (i32, i32)>,
|
||||||
pub comments: Vec<Comment>,
|
pub comments: Vec<Comment>,
|
||||||
pub frozen_rows: i32,
|
pub frozen_rows: i32,
|
||||||
pub frozen_columns: i32,
|
pub frozen_columns: i32,
|
||||||
@@ -226,7 +217,10 @@ pub enum Cell {
|
|||||||
// Error Message: "Not implemented function"
|
// Error Message: "Not implemented function"
|
||||||
m: String,
|
m: String,
|
||||||
},
|
},
|
||||||
// TODO: Array formulas
|
Merged {
|
||||||
|
r: i32,
|
||||||
|
c: i32,
|
||||||
|
}, // TODO: Array formulas
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Cell {
|
impl Default for Cell {
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ use crate::{
|
|||||||
types::{Area, CellReferenceIndex},
|
types::{Area, CellReferenceIndex},
|
||||||
utils::{is_valid_column_number, is_valid_row},
|
utils::{is_valid_column_number, is_valid_row},
|
||||||
},
|
},
|
||||||
model::Model,
|
model::{CellStructure, Model},
|
||||||
types::{
|
types::{
|
||||||
Alignment, BorderItem, CellType, Col, HorizontalAlignment, SheetProperties, SheetState,
|
Alignment, BorderItem, CellType, Col, HorizontalAlignment, SheetProperties, SheetState,
|
||||||
Style, VerticalAlignment, WebUser,
|
Style, VerticalAlignment,
|
||||||
},
|
},
|
||||||
utils::is_valid_hex_color,
|
utils::is_valid_hex_color,
|
||||||
};
|
};
|
||||||
@@ -293,11 +293,6 @@ impl UserModel {
|
|||||||
self.model.workbook.name = name.to_string();
|
self.model.workbook.name = name.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set users
|
|
||||||
pub fn set_users(&mut self, users: &[WebUser]) {
|
|
||||||
self.model.workbook.users = users.to_vec();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Undoes last change if any, places the change in the redo list and evaluates the model if needed
|
/// Undoes last change if any, places the change in the redo list and evaluates the model if needed
|
||||||
///
|
///
|
||||||
/// See also:
|
/// See also:
|
||||||
@@ -1874,6 +1869,57 @@ impl UserModel {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Merges cells
|
||||||
|
pub fn merge_cells(
|
||||||
|
&mut self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let old_data = Vec::new();
|
||||||
|
let diff_list = vec![Diff::MergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
old_data,
|
||||||
|
}];
|
||||||
|
self.model.merge_cells(sheet, row, column, width, height)?;
|
||||||
|
self.push_diff_list(diff_list);
|
||||||
|
self.evaluate_if_not_paused();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if cell is part of a merged cell
|
||||||
|
pub fn get_cell_structure(&self, sheet: u32, row: i32, column: i32) -> Result<CellStructure, String> {
|
||||||
|
self.model.get_cell_structure(sheet, row, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unmerges cells
|
||||||
|
pub fn unmerge_cells(&mut self, sheet: u32, row: i32, column: i32) -> Result<(), String> {
|
||||||
|
let (width, height) = self
|
||||||
|
.model
|
||||||
|
.workbook
|
||||||
|
.worksheet(sheet)?
|
||||||
|
.merged_cells
|
||||||
|
.get(&(row, column))
|
||||||
|
.ok_or("No merged cells found")?;
|
||||||
|
let diff_list = vec![Diff::UnmergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width: *width,
|
||||||
|
height: *height,
|
||||||
|
}];
|
||||||
|
self.model.unmerge_cells(sheet, row, column)?;
|
||||||
|
self.push_diff_list(diff_list);
|
||||||
|
self.evaluate_if_not_paused();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// **** Private methods ****** //
|
// **** Private methods ****** //
|
||||||
|
|
||||||
pub(crate) fn push_diff_list(&mut self, diff_list: DiffList) {
|
pub(crate) fn push_diff_list(&mut self, diff_list: DiffList) {
|
||||||
@@ -2117,7 +2163,6 @@ impl UserModel {
|
|||||||
worksheet.frozen_rows = old_data.frozen_rows;
|
worksheet.frozen_rows = old_data.frozen_rows;
|
||||||
worksheet.state = old_data.state.clone();
|
worksheet.state = old_data.state.clone();
|
||||||
worksheet.color = old_data.color.clone();
|
worksheet.color = old_data.color.clone();
|
||||||
worksheet.merge_cells = old_data.merge_cells.clone();
|
|
||||||
worksheet.shared_formulas = old_data.shared_formulas.clone();
|
worksheet.shared_formulas = old_data.shared_formulas.clone();
|
||||||
self.model.reset_parsed_structures();
|
self.model.reset_parsed_structures();
|
||||||
|
|
||||||
@@ -2168,6 +2213,34 @@ impl UserModel {
|
|||||||
self.model.delete_row_style(*sheet, *row)?;
|
self.model.delete_row_style(*sheet, *row)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Diff::MergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
old_data,
|
||||||
|
} => {
|
||||||
|
needs_evaluation = true;
|
||||||
|
self.model.unmerge_cells(*sheet, *row, *column)?;
|
||||||
|
// for (r, c, v) in old_data.iter() {
|
||||||
|
// self.model
|
||||||
|
// .workbook
|
||||||
|
// .worksheet_mut(*sheet)?
|
||||||
|
// .update_cell(*r, *c, v.clone())?;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
Diff::UnmergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
} => {
|
||||||
|
needs_evaluation = true;
|
||||||
|
self.model
|
||||||
|
.merge_cells(*sheet, *row, *column, *width, *height)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if needs_evaluation {
|
if needs_evaluation {
|
||||||
@@ -2369,6 +2442,34 @@ impl UserModel {
|
|||||||
} => {
|
} => {
|
||||||
self.model.delete_row_style(*sheet, *row)?;
|
self.model.delete_row_style(*sheet, *row)?;
|
||||||
}
|
}
|
||||||
|
Diff::MergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
old_data: _,
|
||||||
|
} => {
|
||||||
|
needs_evaluation = true;
|
||||||
|
self.model
|
||||||
|
.merge_cells(*sheet, *row, *column, *width, *height)?;
|
||||||
|
// for (r, c, v) in old_data.iter() {
|
||||||
|
// self.model
|
||||||
|
// .workbook
|
||||||
|
// .worksheet_mut(*sheet)?
|
||||||
|
// .update_cell(*r, *c, v.clone())?;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
Diff::UnmergeCells {
|
||||||
|
sheet,
|
||||||
|
row,
|
||||||
|
column,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
} => {
|
||||||
|
needs_evaluation = true;
|
||||||
|
self.model.unmerge_cells(*sheet, *row, *column)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,21 @@ pub(crate) enum Diff {
|
|||||||
new_scope: Option<u32>,
|
new_scope: Option<u32>,
|
||||||
new_formula: String,
|
new_formula: String,
|
||||||
},
|
},
|
||||||
// FIXME: we are missing SetViewDiffs
|
MergeCells {
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
old_data: Vec<(Cell, Style)>,
|
||||||
|
},
|
||||||
|
UnmergeCells {
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
}, // FIXME: we are missing SetViewDiffs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type DiffList = Vec<Diff>;
|
pub(crate) type DiffList = Vec<Diff>;
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::expressions::utils::{is_valid_column_number, is_valid_row};
|
use crate::{
|
||||||
|
expressions::utils::{is_valid_column_number, is_valid_row},
|
||||||
|
CellStructure,
|
||||||
|
};
|
||||||
|
|
||||||
use super::common::UserModel;
|
use super::common::UserModel;
|
||||||
|
|
||||||
@@ -97,26 +100,47 @@ impl UserModel {
|
|||||||
if !is_valid_row(row) {
|
if !is_valid_row(row) {
|
||||||
return Err(format!("Invalid row: '{row}'"));
|
return Err(format!("Invalid row: '{row}'"));
|
||||||
}
|
}
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
let worksheet = self.model.workbook.worksheet_mut(sheet)?;
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
let structure = worksheet.get_cell_structure(row, column)?;
|
||||||
|
// check if the selected cell is a merged cell
|
||||||
|
let [row_start, columns_start, row_end, columns_end] = match structure {
|
||||||
|
CellStructure::Simple => [row, column, row, column],
|
||||||
|
CellStructure::Merged {
|
||||||
|
row: row_start,
|
||||||
|
column: column_start,
|
||||||
|
} => {
|
||||||
|
let (width, height) = match worksheet.merged_cells.get(&(row_start, column_start)) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return Err(format!("Merged cell not found: ({row_start}, {column_start}) when clicking at ({row}, {column}).")),
|
||||||
|
};
|
||||||
|
let row_end = row_start + height - 1;
|
||||||
|
let column_end = column_start + width - 1;
|
||||||
|
[row_start, column_start, row_end, column_end]
|
||||||
}
|
}
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet_mut(sheet) {
|
CellStructure::MergedRoot { width, height } => {
|
||||||
|
let row_start = row;
|
||||||
|
let columns_start = column;
|
||||||
|
let row_end = row + height - 1;
|
||||||
|
let columns_end = column + width - 1;
|
||||||
|
[row_start, columns_start, row_end, columns_end]
|
||||||
|
}
|
||||||
|
};
|
||||||
if let Some(view) = worksheet.views.get_mut(&0) {
|
if let Some(view) = worksheet.views.get_mut(&0) {
|
||||||
view.row = row;
|
view.row = row_start;
|
||||||
view.column = column;
|
view.column = columns_start;
|
||||||
view.range = [row, column, row, column];
|
view.range = [row_start, columns_start, row_end, columns_end];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the selected range. Note that the selected cell must be in one of the corners.
|
/// Sets the selected range. Note that the selected cell must be in one of the corners.
|
||||||
pub fn set_selected_range(
|
pub fn set_selected_range(
|
||||||
&mut self,
|
&mut self,
|
||||||
start_row: i32,
|
row_start: i32,
|
||||||
start_column: i32,
|
column_start: i32,
|
||||||
end_row: i32,
|
row_end: i32,
|
||||||
end_column: i32,
|
column_end: i32,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
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
|
||||||
@@ -124,42 +148,72 @@ impl UserModel {
|
|||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
if !is_valid_column_number(start_column) {
|
if !is_valid_column_number(column_start) {
|
||||||
return Err(format!("Invalid column: '{start_column}'"));
|
return Err(format!("Invalid column: '{column_start}'"));
|
||||||
}
|
}
|
||||||
if !is_valid_row(start_row) {
|
if !is_valid_row(row_start) {
|
||||||
return Err(format!("Invalid row: '{start_row}'"));
|
return Err(format!("Invalid row: '{row_start}'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_valid_column_number(end_column) {
|
if !is_valid_column_number(column_end) {
|
||||||
return Err(format!("Invalid column: '{end_column}'"));
|
return Err(format!("Invalid column: '{column_end}'"));
|
||||||
|
}
|
||||||
|
if !is_valid_row(row_end) {
|
||||||
|
return Err(format!("Invalid row: '{row_end}'"));
|
||||||
|
}
|
||||||
|
let mut start_row = row_start;
|
||||||
|
let mut start_column = column_start;
|
||||||
|
let mut end_row = row_end;
|
||||||
|
let mut end_column = column_end;
|
||||||
|
let worksheet = self.model.workbook.worksheet_mut(sheet)?;
|
||||||
|
let merged_cells = &worksheet.merged_cells;
|
||||||
|
if !merged_cells.is_empty() {
|
||||||
|
// We need to check if there are merged cells in the selected range
|
||||||
|
for row in row_start..=row_end {
|
||||||
|
for column in column_start..=column_end {
|
||||||
|
let structure = &worksheet.get_cell_structure(row, column)?;
|
||||||
|
match structure {
|
||||||
|
CellStructure::Simple => {}
|
||||||
|
CellStructure::Merged { row: r, column: c } => {
|
||||||
|
// The selected range must contain the merged cell
|
||||||
|
let (width, height) = match merged_cells.get(&(*r, *c)) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return Err(format!("Merged cell not found: ({r}, {c}) when selecting range ({start_row}, {start_column}, {end_row}, {end_column}).")),
|
||||||
|
};
|
||||||
|
start_row = start_row.min(*r);
|
||||||
|
start_column = start_column.min(*c);
|
||||||
|
end_row = end_row.max(*r + height - 1);
|
||||||
|
end_column = end_column.max(*c + width - 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
CellStructure::MergedRoot { width, height } => {
|
||||||
|
// The selected range must contain the merged cell
|
||||||
|
end_row = end_row.max(row + height - 1);
|
||||||
|
end_column = end_column.max(column + width - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !is_valid_row(end_row) {
|
|
||||||
return Err(format!("Invalid row: '{end_row}'"));
|
|
||||||
}
|
}
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
|
||||||
}
|
}
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet_mut(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get_mut(&0) {
|
if let Some(view) = worksheet.views.get_mut(&0) {
|
||||||
let selected_row = view.row;
|
// let selected_row = view.row;
|
||||||
let selected_column = view.column;
|
// let selected_column = view.column;
|
||||||
// The selected cells must be on one of the corners of the selected range:
|
// // The selected cells must be on one of the corners of the selected range:
|
||||||
if selected_row != start_row && selected_row != end_row {
|
// if selected_row != start_row && selected_row != end_row {
|
||||||
return Err(format!(
|
// return Err(format!(
|
||||||
"The selected cells is not in one of the corners. Row: '{}' and row range '({}, {})'",
|
// "The selected cells is not in one of the corners. Row: '{}' and row range '({}, {})'",
|
||||||
selected_row, start_row, end_row
|
// selected_row, start_row, end_row
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
if selected_column != start_column && selected_column != end_column {
|
// if selected_column != start_column && selected_column != end_column {
|
||||||
return Err(format!(
|
// return Err(format!(
|
||||||
"The selected cells is not in one of the corners. Column '{}' and column range '({}, {})'",
|
// "The selected cells is not in one of the corners. Column '{}' and column range '({}, {})'",
|
||||||
selected_column, start_column, end_column
|
// selected_column, start_column, end_column
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
view.range = [start_row, start_column, end_row, end_column];
|
view.range = [start_row, start_column, end_row, end_column];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::constants::{self, LAST_COLUMN, LAST_ROW};
|
use crate::constants::{self, LAST_COLUMN, LAST_ROW};
|
||||||
use crate::expressions::types::CellReferenceIndex;
|
use crate::expressions::types::CellReferenceIndex;
|
||||||
use crate::expressions::utils::{is_valid_column_number, is_valid_row};
|
use crate::expressions::utils::{is_valid_column_number, is_valid_row};
|
||||||
|
use crate::CellStructure;
|
||||||
use crate::{expressions::token::Error, types::*};
|
use crate::{expressions::token::Error, types::*};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -38,6 +39,24 @@ impl Worksheet {
|
|||||||
self.sheet_data.get(&row)?.get(&column)
|
self.sheet_data.get(&row)?.get(&column)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_cell_structure(&self, row: i32, column: i32) -> Result<CellStructure, String> {
|
||||||
|
if let Some((width, height)) = self.merged_cells.get(&(row, column)) {
|
||||||
|
return Ok(CellStructure::MergedRoot {
|
||||||
|
width: *width,
|
||||||
|
height: *height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let cell = self.cell(row, column);
|
||||||
|
if let Some(Cell::Merged { r, c }) = cell {
|
||||||
|
return Ok(CellStructure::Merged {
|
||||||
|
row: *r,
|
||||||
|
column: *c,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(CellStructure::Simple)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn cell_mut(&mut self, row: i32, column: i32) -> Option<&mut Cell> {
|
pub(crate) fn cell_mut(&mut self, row: i32, column: i32) -> Option<&mut Cell> {
|
||||||
self.sheet_data.get_mut(&row)?.get_mut(&column)
|
self.sheet_data.get_mut(&row)?.get_mut(&column)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pyroncalc"
|
name = "pyroncalc"
|
||||||
version = "0.5.6"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
||||||
@@ -13,8 +13,7 @@ crate-type = ["cdylib"]
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
xlsx = { package= "ironcalc", path = "../../xlsx", version = "0.5.0" }
|
xlsx = { package= "ironcalc", path = "../../xlsx", version = "0.5.0" }
|
||||||
pyo3 = { version = "0.25", features = ["extension-module"] }
|
pyo3 = { version = "0.23", features = ["extension-module"] }
|
||||||
bitcode = "0.6.3"
|
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "ironcalc"
|
name = "ironcalc"
|
||||||
version = "0.5.6"
|
version = "0.5.0"
|
||||||
description = "Create, edit and evaluate Excel spreadsheets"
|
description = "Create, edit and evaluate Excel spreadsheets"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
keywords = [
|
keywords = [
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use pyo3::exceptions::PyException;
|
|||||||
use pyo3::{create_exception, prelude::*, wrap_pyfunction};
|
use pyo3::{create_exception, prelude::*, wrap_pyfunction};
|
||||||
|
|
||||||
use types::{PySheetProperty, PyStyle};
|
use types::{PySheetProperty, PyStyle};
|
||||||
use xlsx::base::types::{Style, Workbook};
|
use xlsx::base::types::Style;
|
||||||
use xlsx::base::{Model, UserModel};
|
use xlsx::base::Model;
|
||||||
|
|
||||||
use xlsx::export::{save_to_icalc, save_to_xlsx};
|
use xlsx::export::{save_to_icalc, save_to_xlsx};
|
||||||
use xlsx::import;
|
use xlsx::import;
|
||||||
@@ -14,60 +14,6 @@ use crate::types::PyCellType;
|
|||||||
|
|
||||||
create_exception!(_ironcalc, WorkbookError, PyException);
|
create_exception!(_ironcalc, WorkbookError, PyException);
|
||||||
|
|
||||||
#[pyclass]
|
|
||||||
pub struct PyUserModel {
|
|
||||||
/// The user model, which is a wrapper around the Model
|
|
||||||
pub model: UserModel,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pymethods]
|
|
||||||
impl PyUserModel {
|
|
||||||
/// Saves the user model to an xlsx file
|
|
||||||
pub fn save_to_xlsx(&self, file: &str) -> PyResult<()> {
|
|
||||||
let model = self.model.get_model();
|
|
||||||
save_to_xlsx(model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Saves the user model to file in the internal binary ic format
|
|
||||||
pub fn save_to_icalc(&self, file: &str) -> PyResult<()> {
|
|
||||||
let model = self.model.get_model();
|
|
||||||
save_to_icalc(model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn apply_external_diffs(&mut self, external_diffs: &[u8]) -> PyResult<()> {
|
|
||||||
self.model
|
|
||||||
.apply_external_diffs(external_diffs)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn flush_send_queue(&mut self) -> Vec<u8> {
|
|
||||||
self.model.flush_send_queue()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_user_input(
|
|
||||||
&mut self,
|
|
||||||
sheet: u32,
|
|
||||||
row: i32,
|
|
||||||
column: i32,
|
|
||||||
value: &str,
|
|
||||||
) -> PyResult<()> {
|
|
||||||
self.model
|
|
||||||
.set_user_input(sheet, row, column, value)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
|
|
||||||
self.model
|
|
||||||
.get_formatted_cell_value(sheet, row, column)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_bytes(&self) -> PyResult<Vec<u8>> {
|
|
||||||
let bytes = self.model.to_bytes();
|
|
||||||
Ok(bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is a model implementing the 'raw' API
|
/// This is a model implementing the 'raw' API
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct PyModel {
|
pub struct PyModel {
|
||||||
@@ -86,12 +32,6 @@ impl PyModel {
|
|||||||
save_to_icalc(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
save_to_icalc(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// To bytes
|
|
||||||
pub fn to_bytes(&self) -> PyResult<Vec<u8>> {
|
|
||||||
let bytes = self.model.to_bytes();
|
|
||||||
Ok(bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Evaluates the workbook
|
/// Evaluates the workbook
|
||||||
pub fn evaluate(&mut self) {
|
pub fn evaluate(&mut self) {
|
||||||
self.model.evaluate()
|
self.model.evaluate()
|
||||||
@@ -309,15 +249,6 @@ pub fn load_from_icalc(file_name: &str) -> PyResult<PyModel> {
|
|||||||
Ok(PyModel { model })
|
Ok(PyModel { model })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
pub fn load_from_bytes(bytes: &[u8]) -> PyResult<PyModel> {
|
|
||||||
let workbook: Workbook =
|
|
||||||
bitcode::decode(bytes).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
let model =
|
|
||||||
Model::from_workbook(workbook).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
Ok(PyModel { model })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates an empty model
|
/// Creates an empty model
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
||||||
@@ -326,43 +257,6 @@ pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
|||||||
Ok(PyModel { model })
|
Ok(PyModel { model })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
pub fn create_user_model(name: &str, locale: &str, tz: &str) -> PyResult<PyUserModel> {
|
|
||||||
let model = UserModel::new_empty(name, locale, tz)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
Ok(PyUserModel { model })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
pub fn create_user_model_from_xlsx(
|
|
||||||
file_path: &str,
|
|
||||||
locale: &str,
|
|
||||||
tz: &str,
|
|
||||||
) -> PyResult<PyUserModel> {
|
|
||||||
let model = import::load_from_xlsx(file_path, locale, tz)
|
|
||||||
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
let model = UserModel::from_model(model);
|
|
||||||
Ok(PyUserModel { model })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
pub fn create_user_model_from_icalc(file_name: &str) -> PyResult<PyUserModel> {
|
|
||||||
let model =
|
|
||||||
import::load_from_icalc(file_name).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
let model = UserModel::from_model(model);
|
|
||||||
Ok(PyUserModel { model })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
pub fn create_user_model_from_bytes(bytes: &[u8]) -> PyResult<PyUserModel> {
|
|
||||||
let workbook: Workbook =
|
|
||||||
bitcode::decode(bytes).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
let model =
|
|
||||||
Model::from_workbook(workbook).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
|
||||||
let user_model = UserModel::from_model(model);
|
|
||||||
Ok(PyUserModel { model: user_model })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
#[allow(clippy::panic)]
|
#[allow(clippy::panic)]
|
||||||
pub fn test_panic() {
|
pub fn test_panic() {
|
||||||
@@ -378,14 +272,7 @@ fn ironcalc(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
m.add_function(wrap_pyfunction!(create, m)?)?;
|
m.add_function(wrap_pyfunction!(create, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(load_from_xlsx, m)?)?;
|
m.add_function(wrap_pyfunction!(load_from_xlsx, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(load_from_icalc, m)?)?;
|
m.add_function(wrap_pyfunction!(load_from_icalc, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(load_from_bytes, m)?)?;
|
|
||||||
m.add_function(wrap_pyfunction!(test_panic, m)?)?;
|
m.add_function(wrap_pyfunction!(test_panic, m)?)?;
|
||||||
|
|
||||||
// User model functions
|
|
||||||
m.add_function(wrap_pyfunction!(create_user_model, m)?)?;
|
|
||||||
m.add_function(wrap_pyfunction!(create_user_model_from_bytes, m)?)?;
|
|
||||||
m.add_function(wrap_pyfunction!(create_user_model_from_xlsx, m)?)?;
|
|
||||||
m.add_function(wrap_pyfunction!(create_user_model_from_icalc, m)?)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,24 +6,3 @@ def test_simple():
|
|||||||
model.evaluate()
|
model.evaluate()
|
||||||
|
|
||||||
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
||||||
|
|
||||||
bytes = model.to_bytes()
|
|
||||||
|
|
||||||
model2 = ic.load_from_bytes(bytes)
|
|
||||||
assert model2.get_formatted_cell_value(0, 1, 1) == "3"
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_user():
|
|
||||||
model = ic.create_user_model("model", "en", "UTC")
|
|
||||||
model.set_user_input(0, 1, 1, "=1+2")
|
|
||||||
model.set_user_input(0, 1, 2, "=A1+3")
|
|
||||||
|
|
||||||
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
|
||||||
assert model.get_formatted_cell_value(0, 1, 2) == "6"
|
|
||||||
|
|
||||||
diffs = model.flush_send_queue()
|
|
||||||
|
|
||||||
model2 = ic.create_user_model("model", "en", "UTC")
|
|
||||||
model2.apply_external_diffs(diffs)
|
|
||||||
assert model2.get_formatted_cell_value(0, 1, 1) == "3"
|
|
||||||
assert model2.get_formatted_cell_value(0, 1, 2) == "6"
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
version = "0.5.3"
|
version = "0.5.0"
|
||||||
authors = ["Nicolas Hatcher <nicolas@theuniverse.today>"]
|
authors = ["Nicolas Hatcher <nicolas@theuniverse.today>"]
|
||||||
description = "IronCalc Web bindings"
|
description = "IronCalc Web bindings"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|||||||
@@ -201,34 +201,24 @@ defined_name_list_types = r"""
|
|||||||
getDefinedNameList(): DefinedName[];
|
getDefinedNameList(): DefinedName[];
|
||||||
"""
|
"""
|
||||||
|
|
||||||
set_users = r"""
|
merged_cells = r"""
|
||||||
/**
|
|
||||||
* @param {any} users
|
|
||||||
*/
|
|
||||||
setUsers(users: any): void;
|
|
||||||
"""
|
|
||||||
|
|
||||||
set_users_types = r"""
|
|
||||||
/**
|
|
||||||
* @param {WebUser[]} users
|
|
||||||
*/
|
|
||||||
setUsers(users: WebUser[]): void;
|
|
||||||
"""
|
|
||||||
|
|
||||||
get_users = r"""
|
|
||||||
/**
|
/**
|
||||||
|
* @param {number} sheet
|
||||||
|
* @param {number} row
|
||||||
|
* @param {number} column
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
getUsers(): any;
|
getCellStructure(sheet: number, row: number, column: number): any;
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
get_users_types = r"""
|
merged_cells_types = r"""
|
||||||
/**
|
/**
|
||||||
* @returns {WebUser[]}
|
* @param {number} sheet
|
||||||
|
* @param {number} row
|
||||||
|
* @param {number} column
|
||||||
|
* @returns {CellStructure}
|
||||||
*/
|
*/
|
||||||
getUsers(): WebUser[];
|
getCellStructure(sheet: number, row: number, column: number): CellStructure;
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def fix_types(text):
|
def fix_types(text):
|
||||||
@@ -245,8 +235,7 @@ def fix_types(text):
|
|||||||
text = text.replace(clipboard, clipboard_types)
|
text = text.replace(clipboard, clipboard_types)
|
||||||
text = text.replace(paste_from_clipboard, paste_from_clipboard_types)
|
text = text.replace(paste_from_clipboard, paste_from_clipboard_types)
|
||||||
text = text.replace(defined_name_list, defined_name_list_types)
|
text = text.replace(defined_name_list, defined_name_list_types)
|
||||||
text = text.replace(set_users, set_users_types)
|
text = text.replace(merged_cells, merged_cells_types)
|
||||||
text = text.replace(get_users, get_users_types)
|
|
||||||
with open("types.ts") as f:
|
with open("types.ts") as f:
|
||||||
types_str = f.read()
|
types_str = f.read()
|
||||||
header_types = "{}\n\n{}".format(header, types_str)
|
header_types = "{}\n\n{}".format(header, types_str)
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ use wasm_bindgen::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use ironcalc_base::{
|
use ironcalc_base::{
|
||||||
expressions::{lexer::util::get_tokens as tokenizer, types::Area, utils::number_to_column},
|
expressions::{lexer::util::get_tokens as tokenizer, types::Area, utils::number_to_column}, types::{CellType, Style}, BorderArea, ClipboardData, UserModel as BaseModel
|
||||||
types::{CellType, Style, WebUser},
|
|
||||||
BorderArea, ClipboardData, UserModel as BaseModel,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn to_js_error(error: String) -> JsError {
|
fn to_js_error(error: String) -> JsError {
|
||||||
@@ -673,17 +671,35 @@ impl Model {
|
|||||||
.map_err(|e| to_js_error(e.to_string()))
|
.map_err(|e| to_js_error(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "setUsers")]
|
#[wasm_bindgen(js_name = "mergeCells")]
|
||||||
pub fn set_users(&mut self, users: JsValue) -> Result<(), JsError> {
|
pub fn merge_cells(
|
||||||
let users: Vec<WebUser> =
|
&mut self,
|
||||||
serde_wasm_bindgen::from_value(users).map_err(|e| to_js_error(e.to_string()))?;
|
sheet: u32,
|
||||||
self.model.set_users(&users);
|
row: i32,
|
||||||
Ok(())
|
column: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
) -> Result<(), JsError> {
|
||||||
|
self.model
|
||||||
|
.merge_cells(sheet, row, column, width, height)
|
||||||
|
.map_err(to_js_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "getUsers")]
|
#[wasm_bindgen(js_name = "unmergeCells")]
|
||||||
pub fn get_users(&self) -> Result<JsValue, JsError> {
|
pub fn unmerge_cells(&mut self, sheet: u32, row: i32, column: i32) -> Result<(), JsError> {
|
||||||
let users = self.model.get_model().workbook.users.clone();
|
self.model
|
||||||
serde_wasm_bindgen::to_value(&users).map_err(|e| to_js_error(e.to_string()))
|
.unmerge_cells(sheet, row, column)
|
||||||
|
.map_err(to_js_error)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = "getCellStructure")]
|
||||||
|
pub fn get_cell_structure(
|
||||||
|
&self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
) -> Result<JsValue, JsError> {
|
||||||
|
let data = self.model.get_cell_structure(sheet, row, column).map_err(|e| to_js_error(e.to_string()))?;
|
||||||
|
serde_wasm_bindgen::to_value(&data).map_err(|e| to_js_error(e.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,9 +235,7 @@ export interface DefinedName {
|
|||||||
formula: string;
|
formula: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebUser {
|
export type CellStructure =
|
||||||
id: string;
|
| "Simple"
|
||||||
sheet: number;
|
| { Merged: { row: number; column: number } }
|
||||||
row: number;
|
| { MergedRoot: { width: number; height: number } };
|
||||||
column: number;
|
|
||||||
}
|
|
||||||
|
|||||||
17
webapp/IronCalc/package-lock.json
generated
17
webapp/IronCalc/package-lock.json
generated
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.5.5",
|
"version": "0.3.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.5.5",
|
"version": "0.3.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.0",
|
||||||
"@ironcalc/wasm": "0.5.3",
|
"@ironcalc/wasm": "file:../../bindings/wasm/pkg",
|
||||||
"@mui/material": "^6.4",
|
"@mui/material": "^6.4",
|
||||||
"@mui/system": "^6.4",
|
"@mui/system": "^6.4",
|
||||||
"i18next": "^23.11.1",
|
"i18next": "^23.11.1",
|
||||||
@@ -43,6 +43,11 @@
|
|||||||
"react-dom": "^18.0.0 || ^19.0.0"
|
"react-dom": "^18.0.0 || ^19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"../../bindings/wasm/pkg": {
|
||||||
|
"name": "@ironcalc/wasm",
|
||||||
|
"version": "0.5.0",
|
||||||
|
"license": "MIT/Apache-2.0"
|
||||||
|
},
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
"version": "4.4.2",
|
"version": "4.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.2.tgz",
|
||||||
@@ -1055,10 +1060,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ironcalc/wasm": {
|
"node_modules/@ironcalc/wasm": {
|
||||||
"version": "0.5.3",
|
"resolved": "../../bindings/wasm/pkg",
|
||||||
"resolved": "https://registry.npmjs.org/@ironcalc/wasm/-/wasm-0.5.3.tgz",
|
"link": true
|
||||||
"integrity": "sha512-ryQKR5ISkSQnnsxBYDnrAUN+GDiAQUx0MzkVpJr7VQXiymOSMZbHfpv5geum1eSJV4gw1ft69syuNolIhVZ4Hg==",
|
|
||||||
"license": "MIT/Apache-2.0"
|
|
||||||
},
|
},
|
||||||
"node_modules/@isaacs/cliui": {
|
"node_modules/@isaacs/cliui": {
|
||||||
"version": "8.0.2",
|
"version": "8.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.5.5",
|
"version": "0.3.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/ironcalc.js",
|
"main": "./dist/ironcalc.js",
|
||||||
"module": "./dist/ironcalc.js",
|
"module": "./dist/ironcalc.js",
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.0",
|
||||||
"@ironcalc/wasm": "0.5.3",
|
"@ironcalc/wasm": "file:../../bindings/wasm/pkg",
|
||||||
"@mui/material": "^6.4",
|
"@mui/material": "^6.4",
|
||||||
"@mui/system": "^6.4",
|
"@mui/system": "^6.4",
|
||||||
"i18next": "^23.11.1",
|
"i18next": "^23.11.1",
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ import {
|
|||||||
ArrowMiddleFromLine,
|
ArrowMiddleFromLine,
|
||||||
DecimalPlacesDecreaseIcon,
|
DecimalPlacesDecreaseIcon,
|
||||||
DecimalPlacesIncreaseIcon,
|
DecimalPlacesIncreaseIcon,
|
||||||
|
MergeCellsIcon,
|
||||||
|
UnmergeCellsIcon,
|
||||||
} from "../../icons";
|
} from "../../icons";
|
||||||
import { theme } from "../../theme";
|
import { theme } from "../../theme";
|
||||||
import BorderPicker from "../BorderPicker/BorderPicker";
|
import BorderPicker from "../BorderPicker/BorderPicker";
|
||||||
@@ -74,6 +76,8 @@ type ToolbarProperties = {
|
|||||||
onClearFormatting: () => void;
|
onClearFormatting: () => void;
|
||||||
onIncreaseFontSize: (delta: number) => void;
|
onIncreaseFontSize: (delta: number) => void;
|
||||||
onDownloadPNG: () => void;
|
onDownloadPNG: () => void;
|
||||||
|
onMergeCells: () => void;
|
||||||
|
onUnmergeCells: () => void;
|
||||||
fillColor: string;
|
fillColor: string;
|
||||||
fontColor: string;
|
fontColor: string;
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
@@ -429,6 +433,28 @@ function Toolbar(properties: ToolbarProperties) {
|
|||||||
>
|
>
|
||||||
<ImageDown />
|
<ImageDown />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
<StyledButton
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onClick={() => {
|
||||||
|
properties.onMergeCells();
|
||||||
|
}}
|
||||||
|
title={t("toolbar.merge_cells")}
|
||||||
|
>
|
||||||
|
<MergeCellsIcon />
|
||||||
|
</StyledButton>
|
||||||
|
<StyledButton
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onClick={() => {
|
||||||
|
properties.onUnmergeCells();
|
||||||
|
}}
|
||||||
|
title={t("toolbar.unmerge_cells")}
|
||||||
|
>
|
||||||
|
<UnmergeCellsIcon />
|
||||||
|
</StyledButton>
|
||||||
|
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
color={properties.fontColor}
|
color={properties.fontColor}
|
||||||
|
|||||||
@@ -567,15 +567,19 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
const {
|
const {
|
||||||
range: [rowStart, columnStart, rowEnd, columnEnd],
|
range: [rowStart, columnStart, rowEnd, columnEnd],
|
||||||
} = model.getSelectedView();
|
} = model.getSelectedView();
|
||||||
// NB: cells outside of the displayed area are not rendered
|
const { topLeftCell, bottomRightCell } =
|
||||||
// I think the only reasonable way to do this would be server side.
|
worksheetCanvas.getVisibleCells();
|
||||||
|
const firstRow = Math.max(rowStart, topLeftCell.row);
|
||||||
|
const firstColumn = Math.max(columnStart, topLeftCell.column);
|
||||||
|
const lastRow = Math.min(rowEnd, bottomRightCell.row);
|
||||||
|
const lastColumn = Math.min(columnEnd, bottomRightCell.column);
|
||||||
let [x, y] = worksheetCanvas.getCoordinatesByCell(
|
let [x, y] = worksheetCanvas.getCoordinatesByCell(
|
||||||
rowStart,
|
firstRow,
|
||||||
columnStart,
|
firstColumn,
|
||||||
);
|
);
|
||||||
const [x1, y1] = worksheetCanvas.getCoordinatesByCell(
|
const [x1, y1] = worksheetCanvas.getCoordinatesByCell(
|
||||||
rowEnd + 1,
|
lastRow + 1,
|
||||||
columnEnd + 1,
|
lastColumn + 1,
|
||||||
);
|
);
|
||||||
const width = (x1 - x) * devicePixelRatio;
|
const width = (x1 - x) * devicePixelRatio;
|
||||||
const height = (y1 - y) * devicePixelRatio;
|
const height = (y1 - y) * devicePixelRatio;
|
||||||
@@ -607,6 +611,29 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
downloadLink.download = "ironcalc.png";
|
downloadLink.download = "ironcalc.png";
|
||||||
downloadLink.click();
|
downloadLink.click();
|
||||||
}}
|
}}
|
||||||
|
onMergeCells={() => {
|
||||||
|
const {
|
||||||
|
sheet,
|
||||||
|
range: [rowStart, columnStart, rowEnd, columnEnd],
|
||||||
|
} = model.getSelectedView();
|
||||||
|
const row = Math.min(rowStart, rowEnd);
|
||||||
|
const column = Math.min(columnStart, columnEnd);
|
||||||
|
|
||||||
|
const width = Math.abs(columnEnd - columnStart) + 1;
|
||||||
|
const height = Math.abs(rowEnd - rowStart) + 1;
|
||||||
|
model.mergeCells(sheet, row, column, width, height);
|
||||||
|
setRedrawId((id) => id + 1);
|
||||||
|
}}
|
||||||
|
onUnmergeCells={() => {
|
||||||
|
const {
|
||||||
|
sheet,
|
||||||
|
range: [rowStart, columnStart, rowEnd, columnEnd],
|
||||||
|
} = model.getSelectedView();
|
||||||
|
const row = Math.min(rowStart, rowEnd);
|
||||||
|
const column = Math.min(columnStart, columnEnd);
|
||||||
|
model.unmergeCells(sheet, row, column);
|
||||||
|
setRedrawId((id) => id + 1);
|
||||||
|
}}
|
||||||
onBorderChanged={(border: BorderOptions): void => {
|
onBorderChanged={(border: BorderOptions): void => {
|
||||||
const {
|
const {
|
||||||
sheet,
|
sheet,
|
||||||
|
|||||||
@@ -236,17 +236,10 @@ const usePointer = (options: PointerSettings): PointerEvents => {
|
|||||||
);
|
);
|
||||||
// we continue to select the new cell
|
// we continue to select the new cell
|
||||||
}
|
}
|
||||||
if (event.shiftKey) {
|
|
||||||
// We are extending the selection
|
|
||||||
options.onAreaSelecting(cell);
|
|
||||||
options.onAreaSelected();
|
|
||||||
} else {
|
|
||||||
// We are selecting a single cell
|
|
||||||
options.onCellSelected(cell, event);
|
options.onCellSelected(cell, event);
|
||||||
isSelecting.current = true;
|
isSelecting.current = true;
|
||||||
worksheetWrapper.setPointerCapture(event.pointerId);
|
worksheetWrapper.setPointerCapture(event.pointerId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[options],
|
[options],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,13 +19,6 @@ import {
|
|||||||
outlineColor,
|
outlineColor,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
|
|
||||||
export interface UserSelection {
|
|
||||||
userId: string;
|
|
||||||
color: string;
|
|
||||||
selection: [number, number, number, number, number]; // [sheet, rowStart, columnStart, rowEnd, columnEnd]
|
|
||||||
div: HTMLDivElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CanvasSettings {
|
export interface CanvasSettings {
|
||||||
model: Model;
|
model: Model;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -393,10 +386,29 @@ export default class WorksheetCanvas {
|
|||||||
column: number,
|
column: number,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
width: number,
|
width1: number,
|
||||||
height: number,
|
height1: number,
|
||||||
): void {
|
): void {
|
||||||
const selectedSheet = this.model.getSelectedSheet();
|
const selectedSheet = this.model.getSelectedSheet();
|
||||||
|
const structure = this.model.getCellStructure(selectedSheet, row, column);
|
||||||
|
if (typeof structure === 'object' && 'Merged' in structure) {
|
||||||
|
// We don't render merged cells
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let width = width1;
|
||||||
|
let height = height1;
|
||||||
|
if (typeof structure === 'object' && 'MergedRoot' in structure) {
|
||||||
|
const root = structure.MergedRoot;
|
||||||
|
const columns = root.width;
|
||||||
|
const rows = root.height;
|
||||||
|
for (let i = 1; i < columns; i += 1) {
|
||||||
|
width += this.getColumnWidth(selectedSheet, column + i);
|
||||||
|
}
|
||||||
|
for (let i = 1; i < rows; i += 1) {
|
||||||
|
height += this.getRowHeight(selectedSheet, row + i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const style = this.model.getCellStyle(selectedSheet, row, column);
|
const style = this.model.getCellStyle(selectedSheet, row, column);
|
||||||
|
|
||||||
let backgroundColor = "#FFFFFF";
|
let backgroundColor = "#FFFFFF";
|
||||||
@@ -1251,33 +1263,6 @@ export default class WorksheetCanvas {
|
|||||||
editor.style.height = `${height - 1}px`;
|
editor.style.height = `${height - 1}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private drawUsersSelection(): void {
|
|
||||||
const users = this.model.getUsers();
|
|
||||||
for (const handle of document.querySelectorAll(
|
|
||||||
".user-selection-ironcalc",
|
|
||||||
))
|
|
||||||
handle.remove();
|
|
||||||
users.forEach((user, index) => {
|
|
||||||
const { sheet, row, column } = user;
|
|
||||||
if (sheet !== this.model.getSelectedSheet()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [x, y] = this.getCoordinatesByCell(row, column);
|
|
||||||
const width = this.getColumnWidth(sheet, column);
|
|
||||||
const height = this.getRowHeight(sheet, row);
|
|
||||||
const div = document.createElement("div");
|
|
||||||
const color = getColor(index + 1);
|
|
||||||
div.className = "user-selection-ironcalc";
|
|
||||||
div.style.left = `${x}px`;
|
|
||||||
div.style.top = `${y}px`;
|
|
||||||
div.style.width = `${width}px`;
|
|
||||||
div.style.height = `${height}px`;
|
|
||||||
div.style.border = `1px solid ${color}`;
|
|
||||||
div.style.position = "absolute";
|
|
||||||
this.canvas.parentElement?.appendChild(div);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private drawCellOutline(): void {
|
private drawCellOutline(): void {
|
||||||
const { cellOutline, areaOutline, cellOutlineHandle } = this;
|
const { cellOutline, areaOutline, cellOutlineHandle } = this;
|
||||||
if (this.workbookState.getEditingCell()) {
|
if (this.workbookState.getEditingCell()) {
|
||||||
@@ -1629,7 +1614,6 @@ export default class WorksheetCanvas {
|
|||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
this.drawCellOutline();
|
this.drawCellOutline();
|
||||||
this.drawUsersSelection();
|
|
||||||
this.drawCellEditor();
|
this.drawCellEditor();
|
||||||
this.drawExtendToArea();
|
this.drawExtendToArea();
|
||||||
this.drawActiveRanges(topLeftCell, bottomRightCell);
|
this.drawActiveRanges(topLeftCell, bottomRightCell);
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import InsertRowBelow from "./insert-row-below.svg?react";
|
|||||||
import IronCalcIcon from "./ironcalc_icon.svg?react";
|
import IronCalcIcon from "./ironcalc_icon.svg?react";
|
||||||
import IronCalcLogo from "./orange+black.svg?react";
|
import IronCalcLogo from "./orange+black.svg?react";
|
||||||
|
|
||||||
|
import MergeCellsIcon from "./merge-cells.svg?react";
|
||||||
|
import UnmergeCellsIcon from "./unmerge-cells.svg?react";
|
||||||
|
|
||||||
import Fx from "./fx.svg?react";
|
import Fx from "./fx.svg?react";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -47,5 +50,7 @@ export {
|
|||||||
InsertRowBelow,
|
InsertRowBelow,
|
||||||
IronCalcIcon,
|
IronCalcIcon,
|
||||||
IronCalcLogo,
|
IronCalcLogo,
|
||||||
|
MergeCellsIcon,
|
||||||
|
UnmergeCellsIcon,
|
||||||
Fx,
|
Fx,
|
||||||
};
|
};
|
||||||
|
|||||||
4
webapp/IronCalc/src/icons/merge-cells.svg
Normal file
4
webapp/IronCalc/src/icons/merge-cells.svg
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8 2L3.33333 2C2.59695 2 2 2.59695 2 3.33333L2 5M8 2L12.6667 2C13.403 2 14 2.59695 14 3.33333L14 5M8 2L8 5M8 14L12.6667 14C13.403 14 14 13.403 14 12.6667L14 11M8 14L3.33333 14C2.59695 14 2 13.403 2 12.6667L2 11M8 14L8 11M2 5L2 11M2 5L14 5M2 11L14 11M14 5L14 11" stroke="#333333" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M5 8L11 8M5 8L6 9L6 7L5 8ZM11 8L10 7L10 9L11 8Z" stroke="#333333" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 564 B |
5
webapp/IronCalc/src/icons/unmerge-cells.svg
Normal file
5
webapp/IronCalc/src/icons/unmerge-cells.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8 2L3.33333 2C2.59695 2 2 2.59695 2 3.33333L2 5M8 2L12.6667 2C13.403 2 14 2.59695 14 3.33333L14 5M8 2L8 5M8 14L12.6667 14C13.403 14 14 13.403 14 12.6667L14 11M8 14L3.33333 14C2.59695 14 2 13.403 2 12.6667L2 11M8 14L8 11M2 5L2 11M2 5L14 5M2 11L14 11M14 5L14 11" stroke="#333333" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M2 8L6 8M6 8L5 7L5 9L6 8Z" stroke="#333333" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M14 8L10 8M10 8L11 7L11 9L10 8Z" stroke="#333333" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 650 B |
@@ -27,6 +27,8 @@
|
|||||||
"vertical_align_top": "Align top",
|
"vertical_align_top": "Align top",
|
||||||
"selected_png": "Export Selected area as PNG",
|
"selected_png": "Export Selected area as PNG",
|
||||||
"wrap_text": "Wrap text",
|
"wrap_text": "Wrap text",
|
||||||
|
"merge_cells": "Merge cells",
|
||||||
|
"unmerge_cells": "Unmerge cells",
|
||||||
"format_menu": {
|
"format_menu": {
|
||||||
"auto": "Auto",
|
"auto": "Auto",
|
||||||
"number": "Number",
|
"number": "Number",
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ pub(crate) fn get_worksheet_xml(
|
|||||||
"<c r=\"{cell_name}\" t=\"e\"{style}><f>{formula}</f><v>{ei}</v></c>"
|
"<c r=\"{cell_name}\" t=\"e\"{style}><f>{formula}</f><v>{ei}</v></c>"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Cell::Merged { .. } => { /* do nothing */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let row_style_str = match row_style_dict.get(row_index) {
|
let row_style_str = match row_style_dict.get(row_index) {
|
||||||
@@ -247,7 +248,7 @@ 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 merge_cell_ref in &worksheet.merged_cells {
|
||||||
merged_cells_str.push(format!("<mergeCell ref=\"{merge_cell_ref}\"/>"))
|
merged_cells_str.push(format!("<mergeCell ref=\"{merge_cell_ref}\"/>"))
|
||||||
}
|
}
|
||||||
let merged_cells_count = merged_cells_str.len();
|
let merged_cells_count = merged_cells_str.len();
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ fn load_xlsx_from_reader<R: Read + std::io::Seek>(
|
|||||||
metadata,
|
metadata,
|
||||||
tables,
|
tables,
|
||||||
views,
|
views,
|
||||||
users: Vec::new(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -989,7 +989,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 merged_cells = load_merged_cells(ws)?;
|
||||||
|
|
||||||
// Conditional Formatting
|
// Conditional Formatting
|
||||||
// <conditionalFormatting sqref="B1:B9">
|
// <conditionalFormatting sqref="B1:B9">
|
||||||
@@ -1028,7 +1028,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,
|
||||||
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user