.NET Core使用Spire.Xls拷贝Excel的sheet表

引入Spire.XLS包,版本13.8.0

using Spire.Xls;
/// 
/// 拷贝Excel的sheet表
/// 
/// 旧文件名-绝对路径
/// 新文件名-绝对路径
/// 拷贝的份数
/// sheet名
protected void CopyExcelSheet(string fileName, string newFileName, int copies, string sheetName = "sheet")
{
    if (copies <= 0)
    {
        return;
    }

    Workbook workbook = new Workbook();
    workbook.LoadFromFile(fileName);
    Worksheet sheet1 = workbook.Worksheets[0];

    for (int i = 0; i < copies; i++)
    {
        Worksheet sheet2 = workbook.Worksheets.Add(sheetName + (i + 1));
        sheet2.CopyFrom(sheet1);
    }
    workbook.SaveToFile(newFileName, FileFormat.Version2010);
}

你可能感兴趣的:(.netcore,excel)