Copying cells with formulas
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?
@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);
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?
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
We were able to respond. Please obtain the latest version and check it.
We were able to respond. Please obtain the latest version and check it.
Hello @MathNya! Thanks for your effort, I'm on holidays right now. As soon as I'm back to office, I'll test it!
Hi, today I updated the dependency, but still I encounter the same problem.
Could you please give me a snippet on how to copy a cell (which contains a formula), to another cell updating the references?
I give you an example, to better clarify the need:
- Cell C1 contains formula =A1+B1
- I want to copy C1 into C2 and get it automatically updated as =A2+B2
Thank you
@erosinnocenti Sorry, I thought this issue was complete since I implemented the relative position calculation for the function. I forgot to reflect it in the copied cells. I will address this in the next update. (I don't think it will take too long.)
@erosinnocenti Sorry, I thought this issue was complete since I implemented the relative position calculation for the function. I forgot to reflect it in the copied cells. I will address this in the next update. (I don't think it will take too long.)
No problem, thanks for your effort.
When the next updated is released I'll try again.
The latest version has been released. Please try it out.
let mut cell = sheet.get_cell("C4").unwrap().clone();
cell.set_coordinate("C5");
sheet.set_cell(cell);
Hello, thanks for the reply. I just tried the new version and I confirm that is working fine. I tested only a basic expression (i.e., =A1+B1) and after copying to row 2 it changed to =A2+B2 as expected.
Frankly speaking, this library is getting really good.
Pity that some of the API is not very Rust-y...
Maybe we can do an overhaul for 2.0...