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: Weirdly, this workaround fails if the original worksheet name includes any characters other than [A-Z0-9_] such as a space or period. For example if it is "Foo Bar" (without quotes). In this case, the PrintArea no longer contains any cells in the copied worksheets.

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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