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

Bug: Spreadsheet with data above StartRow causes column headers to be duplicated #1587

Open
dbrennand opened this issue Apr 11, 2024 · 7 comments
Assignees
Labels

Comments

@dbrennand
Copy link
Contributor

Hey @dfinke

Hope you're keeping well 🙂

I've noticed some odd behaviour using Import-Excel ... -StartRow 3 with an Excel spreadsheet which has the following layout:

Sheet1

image

There are no rows containing data after the table headers however, when I import this spreadsheet it produces the following output:

Import-Excel -Path "Issue.xlsx" -WorksheetName "Sheet1" -StartRow 3

# Output
System Name          :
RAID Group Name      :
RAID Level           :
# LUNs               :
# Disks              :
Raw Capacity (GB)    :
Usable Capacity (GB) :
Used Capacity (GB)   :
Free Capacity (GB)   :
Throughput (IOPS)    :
Defragmented (%)     :

System Name          : System Name
RAID Group Name      : RAID Group Name
RAID Level           : RAID Level
# LUNs               : # LUNs
# Disks              : # Disks
Raw Capacity (GB)    : Raw Capacity (GB)
Usable Capacity (GB) : Usable Capacity (GB)
Used Capacity (GB)   : Used Capacity (GB)
Free Capacity (GB)   : Free Capacity (GB)
Throughput (IOPS)    : Throughput (IOPS)
Defragmented (%)     : Defragmented (%)

Sheet1 (2)

image

This is working as expected and the warning is shown:

Import-Excel -Path "Issue.xlsx" -WorksheetName "Sheet1 (2)"
# Output
WARNING: Worksheet 'Sheet1 (2)' in workbook '...\Issue.xlsx' contains no data in the rows after top row '1'

I think this issue is related to there being some data above the StartRow 3 and the logic in this else statement of the Import-Excel cmdlet doesn't account for this case?

This issue occurs on the latest module version:

PS> gmo | where name -eq ImportExcel

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     7.8.6      ImportExcel                         {Add-ConditionalFormatting, Add-ExcelChart, Add-ExcelDataValidationRule, Add-ExcelName...}
@dfinke
Copy link
Owner

dfinke commented Apr 14, 2024

@dbrennand Thanks for using the Excel module.

My guess is the logic when using -StartRow does not pass thru the checks. Highly possible. That is early organic code.

No ETA on this.

@scriptingstudio
Copy link

I did not dig enough deep but inserting expression if ($StartRow -eq $EndRow) {$rows = 0} after line 182 would resolve the issue and would give some hints to further exploration.

@dfinke
Copy link
Owner

dfinke commented Apr 16, 2024

Thanks @scriptingstudio for checking that. I'll put this on the list. Need to see if there are tests, doubt it.

@dfinke dfinke self-assigned this Apr 16, 2024
@dfinke dfinke added the bug label Apr 16, 2024
dbrennand added a commit to dbrennand/ImportExcel that referenced this issue Apr 17, 2024
@dbrennand
Copy link
Contributor Author

dbrennand commented Apr 17, 2024

@scriptingstudio @dfinke - Pushed a fix for this in master...dbrennand:ImportExcel:fix/#1587

With this change the expected warning is now showing:

Import-Excel -Path "Issue.xlsx" -WorksheetName "Sheet1" -StartRow 3
WARNING: Worksheet 'Sheet1' in workbook 'Issue.xlsx' contains no data in the rows after top row '3'

Previous behaviour is also preserved:

Import-Excel -Path "Issue.xlsx" -WorksheetName "Sheet1 (2)"
WARNING: Worksheet 'Sheet1 (2)' in workbook 'Issue.xlsx' contains no data in the rows after top row '1'

dfinke added a commit that referenced this issue Apr 17, 2024
@dfinke
Copy link
Owner

dfinke commented Apr 17, 2024

Thanks @dbrennand! I just created a branch to take a look. Were you able to take a look at the tests to see if there were any that tested this code?

@dbrennand
Copy link
Contributor Author

Thanks @dbrennand! I just created a branch to take a look. Were you able to take a look at the tests to see if there were any that tested this code?

https://github.com/search?q=repo%3Adfinke%2FImportExcel%20path%3A%2F%5E__tests__%5C%2F%2F%20StartRow&type=code

There are a couple of tests which already include -StartRow - I will add the problematic workbook and include a new test for this.

@dfinke
Copy link
Owner

dfinke commented May 27, 2024

It needs additional tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants