C# - Transpose excel table using Interop

2019-08-27 00:28发布

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?

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

1条回答
Explosion°爆炸
2楼-- · 2019-08-27 00:52

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

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

查看更多
登录 后发表回答