I have a question about copy worksheet, I have tried several ways to perform.
Scenario
Read Excel Template File (Sample.xlsx) with Worksheet "@SAMPLE", Copy the worksheet and add into same Workbook.
Method 1 - Clone Method
xlBook.Worksheets["@SAMPLE"].Clone(xlBook.Worksheets["@SAMPLE"].Parent);
xlBook.Worksheets["@SAMPLE"].Name = "ABC123"
... To Next Iteration
xlBook.Worksheets["@SAMPLE"].Clone(xlBook.Worksheets["@SAMPLE"].Parent);
xlBook.Worksheets["@SAMPLE"].Name = "ABC456"
Outcome: Exception Throw... The given key was not present in the dictionary.
Method 2 - Add Copy
xlBook.Worksheets.AddCopy(xlBook.Worksheets["@SAMPLE"]);
Method 3 - Add
Worksheet xlSheet = xlBook.Worksheets["@SAMPLE"];
xlBook.Worksheet.Add(xlSheet)
Same Outcome with 2 & 3: Exception Throw... Object reference not set to an instance of an object.
But the Worksheet added.
* Can anyone suggest a solution for me? Thanks a lot.