C# Transpose() 方法来转置excel表格中的行和列 [英] C# Transpose() method to transpose rows and columns in excel sheet

查看:19
本文介绍了C# Transpose() 方法来转置excel表格中的行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转置 Excel 工作表的行和列并保存.我想为此使用 C# transpose() 方法.任何人都可以通过示例告诉它如何在 C# 中使用,语法是什么,应该创建什么对象来调用 transpose() 方法?

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 Tools for Office/Excel DNA/Managed XLL 等包含在 C# 中

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;

这篇关于C# Transpose() 方法来转置excel表格中的行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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