-
Notifications
You must be signed in to change notification settings - Fork 399
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
Export-Excel accepts too long worksheetnames, leading to problems later on #1656
Comments
Could you provide a small script, data that repros this? |
$ErrorActionPreference = 'Continue'
$test = [pscustomobject]@{
column1 = "Data"
}
Remove-Item C:\Temp\test.xlsx -ErrorAction SilentlyContinue
try { $WSName = "test"*8; $test | Export-Excel -Path c:\temp\test.xlsx -WorksheetName $WSName } catch { "Worksheet $WSName not created"; $error[0] }
try { $WSName = "test"*8; $test | Export-Excel -Path c:\temp\test.xlsx -WorksheetName $WSName } catch { "Worksheet $WSName not created"; $error[0] }
try { $WSName = "test"*9; $test | Export-Excel -Path c:\temp\test.xlsx -WorksheetName $WSName } catch { "Worksheet $WSName not created"; $error[0] }
try { $WSName = "blah"*8; $test | Export-Excel -Path c:\temp\test.xlsx -WorksheetName $WSName } catch { "Worksheet $WSName not created"; $error[0] } First export will create the Excel file with a warning Output:
|
@ildjarnisdead thanks for the repro. I would add a pre-step to handle the size of the worksheet name so it is of correct length. I'll take a look and suspect this may be a problematic change. |
Excel only supports worksheets up to 31 characters, but Export-Excel allows longer worksheetnames. The first time this happens, a warning is given, but if, in another call, a worksheetname is used which results in the same abbreviated name, an error occurs.
This could be prevented by disallowing WorksheetNames longer than 31 characters.
This results in:
But when I then do:
this results in an Error that does not show the actual problem:
The text was updated successfully, but these errors were encountered: