Given the following scenario:
For now I was able to add an empty worksheet to my destination file like this:
if (FileExists(outputFile) && FileExists(inputFile))
{
var inputPackage = new ExcelPackage(inputFile);
var outputPackage = new ExcelPackage(outputFile);
var summaryInputWorksheet = inputPackage.Workbook.Worksheets[ExcelSummaryHelper.SummaryWorksheet];
outputPackage.Workbook.Worksheets.Add(summaryInputWorksheet.Name);
outputPackage.Workbook.Worksheets.MoveToEnd(summaryInputWorksheet.Name);
outputPackage.Save();
}
What's the best approach to copy the content of workshToCopy from source.xlsx to destination.xlsx's new worksheet using the EPPlus library ?
The following are the steps to perform this operation. Create an object of the Workbook class and load the source Excel file. Create another object of the Workbook class and load the destination Excel file. Copy worksheet from source to destination workbook using destinationWorkbook.
EPPlus does not work with the XLS format. Only XLSX. You'll need to find a new library.
EPPlus is a very helpful open-source 3rd party DLL for writing data to excel. EPPlus supports multiple properties of spreadsheets like cell ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption, pivot tables, data validation, conditional formatting, formula calculation, etc.
Solved.
There's an overload for the Add method on the ExcelWorksheets class that looks like this:
ExcelWorksheets.Add(string Name, ExcelWorksheet Copy)
Can't believe I haven't seen it.
Couldn't you just clone the existing one?
ExcelWorksheets clonedWorksheet = currentExcelWorksheet.Clone();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With