开发者

How to put three Excel worksheets under one workbook

开发者 https://www.devze.com 2023-01-10 17:44 出处:网络
I have three Excel worksheets whic开发者_运维问答h I want to merge under a single workbook.If you need to do this in C#, have a look at Merge Excel Files Into One for some ideas.

I have three Excel worksheets whic开发者_运维问答h I want to merge under a single workbook.


If you need to do this in C#, have a look at Merge Excel Files Into One for some ideas.

You will need the Microsoft Excel Interop library. I found the following example at 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();

Do a search for the Excel.Workseet.Copy() method. This should get you going down the needed code path.

Good luck!


  1. Open all of the workbooks at once
  2. Then right-click on the name of the first sheet you wish to copy and choose Move or Copy...
  3. In the To book drop-down select the book you wish to copy to
  4. Tick the box that says Create a copy
  5. Press OK
  6. Repeat steps 2-5 for the other 2 sheets
0

精彩评论

暂无评论...
验证码 换一张
取 消