Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Combine Specific Worksheets of Excel Files using C#
// Open Excel A file.
Workbook excelA = new Workbook("Excel A.xlsx");
// Open Excel B file.
Workbook excelB = new Workbook("Excel B.xlsx");
// Create destination Workbook.
Workbook destWorkbook = new Workbook();
// First worksheet is added by default to the Workbook. Add the second worksheet.
// Copy the Sales worksheet of Excel A file to destination file.
// Copy the Sales worksheet of Excel B file to destination file.
// By default, the worksheet names are "Sheet1" and "Sheet2" respectively.
// Lets give them meaningful names.
destWorkbook.Worksheets[0].Name = excelA.FileName + " - Sales";
destWorkbook.Worksheets[1].Name = excelB.FileName + " - Sales";
// Save the destination file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment