I apologize. Indeed the worksheet does not exist.
I ran the sample code by cooper360 and the exception appears to take place in ClosedXml.Excel.XLRowsCollection.Add().
It also throws the exception when trying to copy to a brand new empty workbook.
It's interesting that it fails on the XLRowsCollection.Add() and not in the XLWorksheetsCollection.Add().
Here is the stack trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary
at ClosedXML.Excel.XLRowsCollection.Add(Int32 key, XLRow value)
at ClosedXML.Excel.XLWorksheet.<>c__DisplayClass3d.<CopyTo>b__39(KeyValuePair
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName, Int32 position)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName)
at ClosedXML_Test.Form2.button1_Click(Object sender, EventArgs e) in C:\Users\rtanenbaum\Documents\Downloads\ClosedXML_TestCopyTo\Form2.cs:line 33
I ran the sample code by cooper360 and the exception appears to take place in ClosedXml.Excel.XLRowsCollection.Add().
It also throws the exception when trying to copy to a brand new empty workbook.
It's interesting that it fails on the XLRowsCollection.Add() and not in the XLWorksheetsCollection.Add().
Here is the stack trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)at ClosedXML.Excel.XLRowsCollection.Add(Int32 key, XLRow value)
at ClosedXML.Excel.XLWorksheet.<>c__DisplayClass3d.<CopyTo>b__39(KeyValuePair
2 kp)
at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable
1 source, Action`1 action)at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName, Int32 position)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName)
at ClosedXML_Test.Form2.button1_Click(Object sender, EventArgs e) in C:\Users\rtanenbaum\Documents\Downloads\ClosedXML_TestCopyTo\Form2.cs:line 33