- NPOI
- Spire.XLS
- Download Sample Code
using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NPOI { class Program { static void Main(string[] args) { //Load workbook IWorkbook workbook = new XSSFWorkbook(new FileStream("../../../Data/Sample.xlsx", FileMode.Open)); //Get the first worksheet ISheet sheet = workbook.GetSheetAt(0); //Copy to a new sheet sheet.CopySheet("copied sheet", true); //Save the file FileStream file = File.Create("Copied.xlsx"); workbook.Write(file); file.Close(); //Launch System.Diagnostics.Process.Start("Copied.xlsx"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Spire.Xls; namespace Spire.XLS { class Program { static void Main(string[] args) { //Load workbook Workbook workbook = new Workbook(); workbook.LoadFromFile("../../../Data/Sample.xlsx"); //Get the first worksheet Worksheet sheet = workbook.Worksheets[0]; //Create a new worksheet Worksheet newSheet = workbook.CreateEmptySheet("Copied sheet"); //Copy worksheet to the new added worksheet newSheet.CopyFrom(sheet); //Save and Launch workbook.SaveToFile("Copied.xlsx", ExcelVersion.Version2013); System.Diagnostics.Process.Start("Copied.xlsx"); } } }