Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Edited Unassigned: Issue while copying worksheets [9333]

$
0
0
Hi,

I am trying to copy worksheets from one workbook to another. But AddWorksheet() & copyTo() methods throws "An item with the same key has already been added" exception while copying.

can anyone figure it out, what is the issue???

Here is the code:
```
var workbook = new XLWorkbook();
WriteStaticSheets(workbook);

public void WriteStaticSheets(XLWorkbook wb)
{
var workbookTemplate = new XLWorkbook("D:\\test.xlsx");
foreach(var ws in workbookTemplate.Worksheets)
{
wb.AddWorksheet(ws); // throws "An item with the same key has already been added" exception
ws.CopyTo(wb,ws.Name); //even this throws the same exception
}
}
```

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>