I want to clone worksheet int my excel template file programatically. When Using NPOI library I can use
    HSSFWorkbook workbook = new HSSFWorkbook(fs, true);
    workbook.CloneSheet(1);
I wonder is there something equivalent to that with EPPlus ExcelWorkbook. I want to copy overall ExcelWorksheet to keep my format and value, not just copy each cell or range of cell manually
Try the ExcelWorksheets.Copy method:
public ExcelWorksheet Copy(ExcelWorkbook workbook, string existingWorksheetName, string newWorksheetName)
{
    ExcelWorksheet worksheet = workbook.Worksheets.Copy(existingWorksheetName, newWorksheetName);
    return worksheet;
}
first u need to open both of workbooks and then u can add the whole worksheet: (example: copy from workbook_1 -> workbook_2)
FileInfo existingFile1 = new FileInfo(path_of_workbook_1);
using (ExcelPackage package = new ExcelPackage(existingFile1 ))
{
     FileInfo existingFile = new FileInfo(path_of_workbook_2);
     using (ExcelPackage package_0 = new ExcelPackage(existingFile))
     {
         ExcelWorksheet worksheet0 = package_0.Workbook.Worksheets["Original Sheet"];
         package.Workbook.Worksheets.Add("Copied Sheet", worksheet0);
     }
}
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