NamedRange.PasteSpecial Method
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)
public Object PasteSpecial (
[OptionalAttribute] XlPasteType Paste,
[OptionalAttribute] XlPasteSpecialOperation Operation,
[OptionalAttribute] Object SkipBlanks,
[OptionalAttribute] Object Transpose
)
Parameters
- Paste
The part of the range to be pasted.
Can be one of the following XlPasteType values:
- Operation
The paste operation.
Can be one of the following XlPasteSpecialOperation values:
- SkipBlanks
true to not have blank cells in the range on the Clipboard pasted into the destination range. The default value is false.
- Transpose
true to transpose rows and columns when the range is pasted. The default value is false.
Optional Parameters
For information on optional parameters, see Understanding Optional Parameters in COM Interop.
The following code example uses the Copy method to copy the contents of a NamedRange control named NamedRange1 to the Clipboard, and then uses the PasteSpecial method to paste these contents into a NamedRange control named NamedRange2. The Operation parameter is set to xlPasteSpecialOperationAdd so that the content of each cell in NamedRange1 is added to the corresponding cell in NamedRange2.
private void CopyAndPasteSpecialRange() { Microsoft.Office.Tools.Excel.NamedRange namedRange1 = this.Controls.AddNamedRange(this.Range["A1", "A3"], "namedRange1"); namedRange1.Value2 = 22; Microsoft.Office.Tools.Excel.NamedRange namedRange2 = this.Controls.AddNamedRange(this.Range["C1", "C3"], "namedRange2"); namedRange2.Value2 = 5; // Copy the contents of namedRange1 to the clipboard, and then // paste the contents into namedRange2, adding each to // the value in namedRange2. namedRange1.Copy(missing); namedRange2.PasteSpecial(Excel.XlPasteType.xlPasteAll, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd, false, false); }