Reputation: 301
Trying to tackle a lot of new tools at once, attempting to split each worksheet in a .xlsx file into individual workbooks.
Is there a simple way to copy the entire worksheet (including images/lines) with spreadsheetlight or EPPlus?
If direct copying one worksheet to another won't work, are you able to copy all cell data into an object and paste it over to the cells of another workbook?
Any advice is greatly appreciated!
Edit: Open to alternatives to Spreadsheetlight as well, looking into EPPlus at the moment.
Upvotes: 2
Views: 1650
Reputation: 14485
EPPlus makes this fairly simple.
Something like this should do it:
using (var sourceExcel = new ExcelPackage(new FileInfo("multisheet.xlsx")))
{
var sheetsToCopy = sourceExcel.Workbook.Worksheets;
foreach(var sheetToCopy in sheetsToCopy)
{
using (var destExcel = new ExcelPackage())
{
destExcel.Workbook.Worksheets.Add(sheetToCopy.Name, sheetToCopy);
destExcel.SaveAs(new FileInfo(sheetToCopy.Name + ".xlsx"));
}
}
}
Upvotes: 1