Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load named ranges in worksheet scope as is, without validation. #429

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions ClosedXML/Excel/NamedRanges/XLNamedRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ internal IXLNamedRange Add(String rangeName, String rangeAddress, String comment

if (!match.Success)
{
if (Worksheet == null || !XLHelper.NamedRangeReferenceRegex.Match(Worksheet.Range(rangeAddress).ToString()).Success)
throw new ArgumentException("For named ranges in the workbook scope, specify the sheet name in the reference.");
var range = Worksheet?.Range(rangeAddress) ?? Workbook.Range(rangeAddress);
if (range == null)
throw new ArgumentException(string.Format("The range address '{0}' for the named range '{1}' is not a valid range.", rangeAddress, rangeName));
else
rangeAddress = Worksheet.Range(rangeAddress).ToString();
{
if (Worksheet == null || !XLHelper.NamedRangeReferenceRegex.Match(range.ToString()).Success)
throw new ArgumentException("For named ranges in the workbook scope, specify the sheet name in the reference.");
else
rangeAddress = Worksheet.Range(rangeAddress).ToString();
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions ClosedXML/Excel/XLWorkbook_Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ private void LoadDefinedNames(Workbook workbook)
else
{
if (!Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges.Any(nr => nr.Name == name))
Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges.Add(name, text, comment).Visible = visible;
(Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges as XLNamedRanges).Add(name, text, comment, true).Visible = visible;
}
}
}
Expand All @@ -1073,7 +1073,6 @@ private void LoadDefinedNames(Workbook workbook)

private IEnumerable<String> validateDefinedNames(IEnumerable<String> definedNames)
{
var fixedNames = new List<String>();
var sb = new StringBuilder();
foreach (string testName in definedNames)
{
Expand Down Expand Up @@ -2399,4 +2398,4 @@ private static Boolean GetBoolean(BooleanPropertyType property)
return false;
}
}
}
}