简体   繁体   中英

C# - Transpose excel table using Interop

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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