C# - Transpose excel table using Interop

不羁岁月 提交于 2019-12-12 04:43:14

问题


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:


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



来源:https://stackoverflow.com/questions/46592498/c-sharp-transpose-excel-table-using-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!