Excel粘贴特殊和添加操作 [英] Excel Paste Special and Add Operation

查看:353
本文介绍了Excel粘贴特殊和添加操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们要向所有excel工作表单元格添加一个数字(例如5)时,您可以复制包含值5的单元格,选择我们想要的其他单元格范围(例如10x10范围),然后右键单击 - 粘贴特别的,然后检查添加操作,然后单击确定。

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.

我想在C#中使用Excel Interop dll将所有选定范围的单元格添加到5中。如何实现?

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

推荐答案

执行粘贴特殊 - >添加操作是相当容易的。假设你已经有一个工作表对象,下面的工作:

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);

您可以找到PasteSpecial方法的完整说明 here

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

这篇关于Excel粘贴特殊和添加操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆