简体   繁体   English

C#-使用Interop转置Excel表

[英]C# - Transpose excel table using Interop

I should transpose a table of an excel sheet in c#. 我应该在C#中转置Excel工作表的表格。 There is a method to do it into the Microsoft.Office.Interop.Excel api, or any other method to do this? 有没有一种方法可以将其添加到Microsoft.Office.Interop.Excel api中,或者有其他方法可以做到这一点?

Edit 编辑

This is my code: 这是我的代码:

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 method exists in the Microsoft.Office.Interop.Excel library. 转置方法存在于Microsoft.Office.Interop.Excel库中。 You may see the usage of it at the below link : 您可能会在以下链接中看到它的用法:

C# Transpose() method to transpose rows and columns in excel sheet C#Transpose()方法转置Excel工作表中的行和列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM