C# – Paste Values as Transpose in Excel

Need to paste values as transpose in excel programmatically using C#?

This post is going to guide you to do so.

What Is Transpose Values in MS Excel?

Transpose values in MS Excel is converting vertical range to a horizontal range or vice versa. It helps you to format data range as per your customized requirements. Below given images shows data transpose visuals clearly.

Data before Transpose

Data after Transpose

This can be done by C# code programming. Below given code snippet pastes excel (“A1:I3”) data range as transpose to range A10.

string copyRange = "A3:I3";
string pasteRange = "A10";

sht.Range[copyRange].Copy();

sht.Range[pasteRange].PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteAll, Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,false,true);

As shown in above code, 4th parameter of Range.PasteSpecial method is set to true. By default, its value is false and setting it to true allows you to paste values as transpose.

You can refer to this link for more information about excel properties using interop c#.

Leave a Reply