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

Commented Unassigned: Bug if worksheet name contains ' character [9220]

$
0
0
If a a worksheet name contains one or more apostroph characters (') and if a print area is defined for that worksheet, then __new XLWorkbook("mybook.xlsx")__ fails.

The problem is in XLWorkbook_Load.cs

```
private static void ParseReference(string item, out string sheetName, out string sheetArea)
{
var sections = item.Trim().Split('!');

// If the worksheet name is "D'Artagnan" (encoded as 'D''Artagnan')
// *all* apostrophs will get stripped and we get "DArtagnan" instead of "D'Artagnan"
sheetName = sections[0].Replace("\'", "");
sheetArea = sections[1];
}
```

This will lead to an exception later in the XLWorksheets.Worksheet method.

The attached xlsx file exposes the bug.
Comments: ** Comment from web user: MichaelWalz **

Proposed fix:

```
private static void ParseReference(string item, out string sheetName, out string sheetArea)
{
var sections = item.Trim().Split('!');
sheetName = sections[0] ;
if (sheetName[0] == '\'')
{
sheetName = sections[0].Substring(1, sections[0].Length - 2);
sheetName = sheetName.Replace("\'\'", "\'");
}

sheetArea = sections[1];
}
```


Viewing all articles
Browse latest Browse all 1877

Trending Articles



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