开发者

Duplicate range in Excel via C#

开发者 https://www.devze.com 2022-12-18 04:08 出处:网络
I have well defined Excel range, let\'s say \"A5:I9\" for example. I would like 开发者_JS百科to multiply the complete rows of these range via C#. \"Multiply\" means to copy the range several times bel

I have well defined Excel range, let's say "A5:I9" for example. I would like 开发者_JS百科to multiply the complete rows of these range via C#. "Multiply" means to copy the range several times below itself, shifting the rest of the document down. Any hint how to do that? I'm fighting with the Range.Insert and Range.Copy methods for quite some time now and in various combinations, but they never behave like I would expect accoring to the documentation!?

cheers, Achim


To shift the rest of the document down I guess you would need to insert the expected amount of rows (five in you example) where you want to paste, before each copy:

// First copy paste with static range values
Range destination = yourWorksheet.get_range("A10",Type.Missing)
yourWorksheet.get_range("A5", "I9").Copy(destination);

Then loop on it while keeping the last "written" line.

0

精彩评论

暂无评论...
验证码 换一张
取 消