C# - 使用Interop转置excel表

时间:2017-10-05 18:28:29

标签: c# excel excel-interop

我应该在c#中转换excel表的表格。有一种方法可以在Microsoft.Office.Interop.Excel api或任何其他方法中执行此操作吗?

修改

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

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

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