Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Commented Issue: PrintArea broken after worksheet copied [14816]

$
0
0
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

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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