Excel Paste Special and Add Operation

戏子无情 提交于 2019-12-11 08:27:00

问题


When we want add a Number (for example 5) to all of excel worksheet cells, you can copy cell containing the value 5, select range of other cells we want (for example a 10x10 Range) and Right click-> Paste special then check add Operation and click OK.

I want to add 5 to all of cells in selected range with Excel Interop dll in C#. How can this be achieved?


回答1:


To perform a Paste Special -> Add operation is fairly easy. Assuming you already have a Worksheet object the following will work:

// Copy the initial value from cell A1

xlWorksheet.get_Range("A1", "A1").Copy(Missing.Value);

// Paste special (with Addition) the value over cells A2 to J11

xlWorksheet.get_Range("A2", "J11").PasteSpecial(Excel.XlPasteType.xlPasteAll,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd, false, false);

You can find a full explanation of the PasteSpecial method here.



来源:https://stackoverflow.com/questions/10147152/excel-paste-special-and-add-operation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!