Handles and warns if auto name range names are also valid Excel ranges

Handles and warns if auto name range names are also valid Excel ranges
This commit is contained in:
dfinke
2016-03-08 17:01:26 -05:00
parent a2ac8c9785
commit ee0dac3b8d

View File

@@ -203,10 +203,15 @@ function Export-Excel {
$totalColumns=$ws.Dimension.Columns
foreach($c in 0..($totalColumns-1)) {
$targetRangeName = "$($script:Header[$c])"
$targetRangeName = "$($script:Header[$c])"
$targetColumn = $c+1
$theCell = $ws.Cells[2,$targetColumn,$totalRows,$targetColumn ]
$ws.Names.Add($targetRangeName, $theCell) | Out-Null
if([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress($targetRangeName)) {
Write-Warning "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property name."
}
}
}