MathNya / umya-spreadsheet

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

Moving cell functionality #125

Closed boseongkim32 closed 10 months ago

boseongkim32 commented 11 months ago

Hi, I had an idea for moving cell functionality, for which I tentatively made a function at the end of spreadsheet.rs in structs. If I wanted to move cells A1:D6 by 2 rows and 3 columns, it would shift all the values by 3 cells to the right, 2 rows down. I was wondering if it would be a good idea to:

check whether the coordinates to move are within range then iterate through the cells, collecting the information repaste the information using set_value

or something alone those lines. thanks!

I also think it would be nice to have merge cell functionality in the future, which I would also love to contribute to

MathNya commented 11 months ago

@boseongkim32 Thank you for your suggestion. Moving cells and merging cells. I would love to adopt both. I will try to implement them in the next few days.

MathNya commented 11 months ago

@boseongkim32 I implemented move_range. Please check it if you have time.

let range = "C5:F9";
let row = 12;
let column = 4;
book.get_sheet_by_name_mut("Sheet1").unwrap().move_range(range, &row, &column);

Also, merge_cells, but there was already a similar function.

book.get_sheet_by_name_mut("Sheet1").unwrap().add_merge_cells("A1:C5");
boseongkim32 commented 11 months ago

Hi, yes move range works! I added a tiny test myself

MathNya commented 11 months ago

Thank you for your prompt confirmation. We will merge the PR as well.