如何将三个Excel工作表放在一个工作簿下

时间:2010-08-10 01:34:02

标签: c# excel com-interop worksheet

我有三个Excel工作表,我想在一个工作簿下合并。

2 个答案:

答案 0 :(得分:2)

如果您需要在C#中执行此操作,请查看Merge Excel Files Into One以获取一些想法。

您将需要Microsoft Excel Interop库。我在http://forums.asp.net/p/1457463/3498328.aspx

找到了以下示例
ApplicationClass excelApplicationClass = new ApplicationClass();
_Workbook finalWorkbook = null;
Workbook workBook = null;
Worksheet workSheet = null;
Worksheet newWorksheet = null;

// Open or create destination WorkBook
finalWorkbook = excelApplicationClass.Workbooks.Open("dest.xlsx", ...);

//Open the source WorkBook
workBook = excelApplicationClass.Workbooks.Open("src.xlsx", ...);

//Open the WorkSheet
workSheet = (Worksheet)workBook.Sheets[1];

int countWorkSheet = finalWorkbook.Worksheets.Count;

newWorksheet = (Worksheet)finalWorkbook.Sheets[countWorkSheet];
workSheet.Copy(Missing.Value, newWorksheet);   //Copy from src to destn

finalWorkbook.Save();
workBook.Save();

搜索Excel.Workseet.Copy()方法。这应该让你沿着所需的代码路径前进。

祝你好运!

答案 1 :(得分:0)

  1. 立即打开所有工作簿
  2. 然后右键单击要复制的第一张表的名称,然后选择Move or Copy...
  3. To book下拉菜单中选择您要复制到的图书
  4. 勾选显示Create a copy
  5. 的复选框
  6. OK
  7. 对其他2张
  8. 重复步骤2-5