Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I deep clone row in .xlsx file using openXML?

I have template.xlsx file which I must modify by adding a few copies of one row in specific index. When I try use clone method for this operation I add a row but each row modify each other. I need to create deep clone of opemxml row object but when I try this I have an error that openxml row object are not serialized. How can I deep clone row in .xlsx file using openXML with serialization or if there is another way to deep clone openxml row object?

like image 330
ElConrado Avatar asked Jan 27 '26 12:01

ElConrado


1 Answers

You can deep clone using .CloneNode(true) on an OpenXmlElement

So if you want to duplicate a row inside a table it will look like

// suppose table an OpenXml Table and row the row you want to clone
table.Append(row.CloneNode(true));

edit : to insert it before a specific row

// suppose r is the row you want to insert it before
r.InsertBeforeSelf(row.CloneNode(true));
like image 150
Maxime Porté Avatar answered Jan 30 '26 00:01

Maxime Porté



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!