EPPlus clone worksheet

Bùi Đức Khánh picture Bùi Đức Khánh · Feb 1, 2018 · Viewed 8.1k times · Source

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

Answer

Cake or Death picture Cake or Death · Feb 1, 2018

Try the ExcelWorksheets.Copy method:

public ExcelWorksheet Copy(ExcelWorkbook workbook, string existingWorksheetName, string newWorksheetName)
{
    ExcelWorksheet worksheet = workbook.Worksheets.Copy(existingWorksheetName, newWorksheetName);
    return worksheet;
}