1

How to copy and duplicate an existing IWorksheet object in SpreadsheetGear?

I want to make identical worksheet based on another worksheet (all values, formulas, named ranges etc. should follow).

Nuts
  • 2,755
  • 6
  • 33
  • 78

1 Answers1

4

You can use the ISheet.CopyAfter/CopyBefore methods to copy a single sheet, in its entirety and including named ranges, to some other location. This "other location" could be within the same workbook as the sheet you are copying; or an entirely different workbook. Example:

// Make copy of "Sheet1" in sourceWorkbook after "Sheet3" in destWorkbook
IWorksheet newSheet = sourceWorkbook.Worksheets["Sheet1"].CopyAfter(destWorkbook.Worksheets["Sheet3"]);
Tim Andersen
  • 3,014
  • 1
  • 15
  • 11
  • What if the destination Workbook is in another WorkbookView? I have and and want to copy Worksheet from wbw1 to wbw2. I am getting an exeption when trying to do that. – Nuts Oct 30 '13 at 07:50
  • It should not matter whether the destination workbook is attached to another WorkbookView or not. You should probably post a new question with a specific test case demonstrating the problem. – Tim Andersen Oct 31 '13 at 21:27