C#-使用Interop转置excel表 [英] C# - Transpose excel table using Interop

查看:275
本文介绍了C#-使用Interop转置excel表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在C#中转置Excel工作表的表格.有没有一种方法可以将其添加到Microsoft.Office.Interop.Excel api中,或者可以通过任何其他方法来做到这一点?

I should transpose a table of an excel sheet in c#. There is a method to do it into the Microsoft.Office.Interop.Excel api, or any other method to do this?

这是我的代码:

string pathFile, range;   

pathFile = @"C:\Users\Administrator\Desktop\" + fileName;

Excel.Application app = new Excel.Application();
Excel.Workbook book = app.Workbooks.Open(pathFile);
Console.WriteLine("Inserire il range delle celle da copiare(sono tutti uguali): ");
range = Console.ReadLine();

Excel.Range rgn = app.get_Range(range);
Object[,] transposeRange = (Object[,])app.WorksheetFunction.Transpose(rgn);
transposeRange = app.ActiveSheet.Range("A1").Resize(transposeRange.GetUpperBound(0), transposeRange.GetUpperBound(1));

推荐答案

Transpose方法存在于Microsoft.Office.Interop.Excel库中.您可能会在以下链接中看到它的用法:

Transpose method exists in the Microsoft.Office.Interop.Excel library. You may see the usage of it at the below link :

C#Transpose()方法在Excel工作表中转置行和列

这篇关于C#-使用Interop转置excel表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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