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!
- Open all of the workbooks at once
- Then right-click on the name of the first sheet you wish to copy and choose
Move or Copy...
- In the
To book
drop-down select the book you wish to copy to - Tick the box that says
Create a copy
- Press
OK
- Repeat steps 2-5 for the other 2 sheets
精彩评论