If I copy a worksheet using Worksheets.Add(name, original), the PrintArea for the original sheet gets screwed up.
Code:
```
string templatePath = "c:\\docWithPrintAreaSetInFirstWorksheet.xlsx";
string newPath = "c:\\newDoc.xlsx";
var package = new ExcelPackage(new FileInfo(templatePath), true);
var original = package.Workbook.Worksheets[1];
package.Workbook.Worksheets.Add("My new worksheet", original)
package.SaveAs(new FileInfo(newPath));
using (var newPackage = new ExcelPackage(new FileInfo(newPath)))
{
var firstSheet = newPackage.Workbook.Worksheets[1];
// this will crash as Current throws an exception
bool b = firstSheet.PrinterSettings.PrintArea.Current != null;
}
```
I'm using EPPlus v3.1.2. Just a hunch, but it might have something to do with line 245 of ExcelWorksheets.cs:
```
// first delete the attribute from the XML
pageSetup.Attributes.Remove(attr);
```
My workaround is to duplicate the original worksheet twice, then delete the original. I then have two worksheets with working PrintAreas.
Thanks
Comments: This should be fixed in the latest source (default branch). The print area is a defined name and it was set in an invalid way. Try it out and let me know if it works for you
Code:
```
string templatePath = "c:\\docWithPrintAreaSetInFirstWorksheet.xlsx";
string newPath = "c:\\newDoc.xlsx";
var package = new ExcelPackage(new FileInfo(templatePath), true);
var original = package.Workbook.Worksheets[1];
package.Workbook.Worksheets.Add("My new worksheet", original)
package.SaveAs(new FileInfo(newPath));
using (var newPackage = new ExcelPackage(new FileInfo(newPath)))
{
var firstSheet = newPackage.Workbook.Worksheets[1];
// this will crash as Current throws an exception
bool b = firstSheet.PrinterSettings.PrintArea.Current != null;
}
```
I'm using EPPlus v3.1.2. Just a hunch, but it might have something to do with line 245 of ExcelWorksheets.cs:
```
// first delete the attribute from the XML
pageSetup.Attributes.Remove(attr);
```
My workaround is to duplicate the original worksheet twice, then delete the original. I then have two worksheets with working PrintAreas.
Thanks
Comments: This should be fixed in the latest source (default branch). The print area is a defined name and it was set in an invalid way. Try it out and let me know if it works for you