C# Transpose() method to transpose rows and columns in excel sheet

后端 未结 3 1988
你的背包
你的背包 2020-12-01 23:00

I want to transpose rows and columns of an excel sheet and save it. I want to use C# transpose() method for this purpose. Can anybody tell how it can be used in C# with exam

3条回答
  •  独厮守ぢ
    2020-12-01 23:41

    your method is part of the Excel object model but included in C# through Visual Studio Tools for Office / Excel DNA / Managed XLL etc

    Object[,] transposedRange = (Object[,])xlApp.WorksheetFunction.Transpose(rng.Value2);
    

    Then paste the transposedRange back into Excel:

    xlApp.ActiveSheet.Range("A1").Resize(transposedRange.GetUpperBound(0), transposedRange.GetUpperBound(1)) = transposedRange;
    

提交回复
热议问题