I have a process that creates about 200 sheets. In the end, I want them all in one workbook. (long story, I know it's not the best design, but I'm stuck with it).
Originally I tried doing just that, one workbook and adding all the sheets, but I kept running out of memory. So I decided to create a workbook for each sheet, and then at the end, combine all of the sheets into one. I thought this would be more efficient, but it takes far longer to copy a sheet than to create it. Almost by a factor of 10 or so, which makes no sense at all. The copy should be very fast I would think. I would have expected the copy to be faster than the create.
Any ideas on this? Due to memory constraints, I think my approach of separate sheets and combining them is the way to go, but the copy is so dreadfully slow.
Originally I tried doing just that, one workbook and adding all the sheets, but I kept running out of memory. So I decided to create a workbook for each sheet, and then at the end, combine all of the sheets into one. I thought this would be more efficient, but it takes far longer to copy a sheet than to create it. Almost by a factor of 10 or so, which makes no sense at all. The copy should be very fast I would think. I would have expected the copy to be faster than the create.
Any ideas on this? Due to memory constraints, I think my approach of separate sheets and combining them is the way to go, but the copy is so dreadfully slow.
XLWorkbook wb = new XLWorkbook(XLEventTracking.Disabled);
foreach (SheetPart mySheetPart in mySheetParts)
{
XLWorkbook wbSource = new XLWorkbook(mySheetPart.FileName, XLEventTracking.Disabled);
foreach (IXLWorksheet copySheet in wbSource.Worksheets)
{
copySheet.CopyTo(wb, copySheet.Name);
}
wbSource.Dispose();
File.Delete(mySheetPart.FileName);
}
wb.SaveAs(FileName + "Final.xlsx");