【问题标题】:C# - Transpose excel table using InteropC# - 使用互操作转置 excel 表
【发布时间】:2017-10-06 04:34:49
【问题描述】:

我应该在 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));

【问题讨论】:

  • 你需要问一个更清楚更详细的问题。
  • 因为我实在不知道你在问什么,所以我只能提供给你这个。 msdn.microsoft.com/en-us/library/…检查复制方法。
  • @Jaberwocky 我通过输入我尝试编写的代码来编辑帖子。我希望你能更好地理解我的问题

标签: c# excel excel-interop


【解决方案1】:

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

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

【讨论】:

  • 我已尝试按照对您链接到我的问题的解释进行操作,但没有成功。我用我写的代码编辑了这篇文章。
猜你喜欢
  • 1970-01-01
  • 2010-12-27
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多