We are using Range.Copy()
method to copy from one worksheet to another
IList<ICell> l = FindCells(template3.Workbook, "1,000.00");
CreateRange(template3.Workbook, l[0].Row, l[0].Column, 1, 1, "SecTotalDeal");
//SetFormulas(template3.Workbook);
foreach (var workSheet in template3.Workbook.Worksheets)
{
Range sourceRange = workSheet.Cells.MaxDisplayRange;
Range destinationRange = newWorkbook.Worksheets["QuoteSummary"].Cells.CreateRange(sourceRange.FirstRow + totalRowCount, sourceRange.FirstColumn, sourceRange.RowCount, sourceRange.ColumnCount);
destinationRange.Copy(sourceRange, new PasteOptions
{
PasteType = PasteType.All
});
destinationRange.CopyStyle(sourceRange);
//totalRowCount = sourceRange.RowCount + totalRowCount + 1;
}
I am also attaching a console application for further analysis, you can check from line no. 170 onwards in Program.cs file where I am creating a named range and then copying it to another workbook.
AsposeTesting.zip (5.6 MB)
Also note that we are using Range.Copy()
since there are cases where we need to copy multiple worksheets into a single worksheet.