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

Improvement import-excel or explain, please #678

Closed
Jireck-npds opened this issue Sep 18, 2019 · 6 comments
Closed

Improvement import-excel or explain, please #678

Jireck-npds opened this issue Sep 18, 2019 · 6 comments

Comments

@Jireck-npds
Copy link

Hello
Improvement of the import-excel function with a "all tabs" parameter that would return a multi-dimensional array with as Key, the tab index as provided by the Get-ExcelSheetInfo function.
or something like that, so you can work on the object.

unless there's another method?

Regards

@jhoneill
Copy link

$hash = @{}
$e=Open-ExcelPackage C:\Users\mcp\desktop\Test.xlsx     
foreach ($sheet in $e.workbook.worksheets) {$hash[$sheet.name]=  Import-Excel -ExcelPackage $e -WorksheetName $sheet.name} 
Close-ExcelPackage $e -NoSave 

If you want the index instead of the name use $hash[$sheet.index]=

Tab indexes begin at 1. This will convert the hash table to a zero based array
$array = $hash[$e.Workbook.Worksheets.name]
But Sheet1 will be in $array[0]

@Jireck-npds
Copy link
Author

Jireck-npds commented Sep 18, 2019

Hello,
Thank you @jhoneill
I try something like that :
$arr = @()
$ok = Get-ExcelSheetInfo -path .\test.xlsx
foreach ($s in $ok) {
$arr[$s.Index]= Import-Excel -path .\test.xlsx -WorksheetName $s.name
}

Thank again for confirmation, i keep also your code.

And i think it's a good improvement for import-excel function to have a parameter like that :

$alltab = import-excel -path .\test.xlsx -tabs

we have with this all option in function :

  • no parameter import last sheet
  • with -WorksheetName import named sheet
  • tabs import all tabs

It's just a idee

@dfinke
Copy link
Owner

dfinke commented Sep 18, 2019

It's a good idea! May write this up as an example or add it as a separate function, Get-AllExcelSheets.

@dfinke dfinke closed this as completed Sep 18, 2019
@Jireck-npds
Copy link
Author

Perfect !
I'm Happy to help you for this great powershell module @dfinke !

@dfinke
Copy link
Owner

dfinke commented Sep 19, 2019

@jhoneill question, should this be an example or supported function? Would you want to take it?

@jhoneill
Copy link

jhoneill commented Sep 20, 2019

I would do it as an example. I think there are multiple ways that people might want to do this so the a function would only be right for some, better to show how it is done and let people roll their own.

I can take it.

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

No branches or pull requests

3 participants