Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Feb 23, 2017 1:22 am

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.

trehanson
 
Posts: 5
Joined: Tue Feb 21, 2017 10:34 am

Thu Feb 23, 2017 3:34 am

Dear trehanson,

Thanks for your inquiry.
I have noticed the issue and posted it to our Dev team, once there is any progress, we will inform you immediately.
Sorry for inconvenience.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS