C#移调()方法来转在excel表格的行和列方法来、表格、excel

2023-09-02 21:10:45 作者:森樹白雲

我要转置行和Excel工作表的列并保存。我想用C#转()方法用于此目的。谁能告诉它如何在C#与示例中使用,什么是语法,什么对象768,16创建调用转()方法?

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 examples, what is the syntax, what object shoud be created to call transpose() method?

感谢你。

推荐答案

你的方法是Excel对象模型的一部分​​,但通过Visual Studio工具用于Office / Excel的DNA /管理XLL等

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

然后粘贴transposedRange返回到Excel中:

Then paste the transposedRange back into Excel:

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