MathNya / umya-spreadsheet

A pure rust library for reading and writing spreadsheet files
MIT License
238 stars 41 forks source link

Copying cells with formulas #187

Open erosinnocenti opened 1 month ago

erosinnocenti commented 1 month ago

Hi! Thanks for this great library. I'm writing an issue to ask help about cloning cells.

I implemented a simple function which iterates through all the cells of a row and clones them. After that, i used get_cell_mut using the coordinates of the target row to create the new cells, and then copied the contents using set_style(from_cell.get_style().clone()), set_cell_value(from_cell.get_cell_value().clone)) etc. The problem is that the formulas are copied but the references are still the same of the original row.

Is there a way to copy cells from position to another updating its formulas references with the row/column offsets?

MathNya commented 1 month ago

@erosinnocenti Thank you for contacting us. Sorry, formulas offsets are not supported. umya-spreadsheet keeps formulas as string.

Although not smart, an example implementation is shown below.

let mut formula = get_cell_value().get_formula();
formula = // Update value
get_cell_value_mut().set_formula(formula);
erosinnocenti commented 1 month ago

Thanks for your reply and the code snippet. Do you think this feature could be implemented in the near future or is it not in your interest?

MathNya commented 1 month ago

The ability to parse formuals has been discussed for some time. However, it is expected to take some time due to the difficulty involved in implementing it. https://github.com/MathNya/umya-spreadsheet/issues/148