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

import-module syntax error in 3 examples #365

Closed
mi-hol opened this issue Jun 25, 2018 · 21 comments
Closed

import-module syntax error in 3 examples #365

mi-hol opened this issue Jun 25, 2018 · 21 comments

Comments

@mi-hol
Copy link

mi-hol commented Jun 25, 2018

After I did
Install-Module ImportExcel as administrator the code in sample: https://github.com/dfinke/ImportExcel/blob/master/Examples/PivotTable/PivotTableWithName.ps1 gives error:

Import-Module ..\..\ImportExcel.psd1 -Force
Import-Module : The specified module '..\..\ImportExcel.psd1' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module ..\..\ImportExcel.psd1 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (..\..\ImportExcel.psd1:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

changing it to

Import-Module ImportExcel.psd1

works as expected :)

@mi-hol
Copy link
Author

mi-hol commented Jun 25, 2018

same issue is present in 2 more files:

Examples/CustomReporting/CustomReport.ps1
Examples/ExcelToSQLInsert/DemoSQLInsert.ps1

@mi-hol mi-hol changed the title Examples/PivotTable/PivotTableWithName.ps1 - import-module syntax error import-module syntax error in 3 examples Jun 25, 2018
@dfinke
Copy link
Owner

dfinke commented Jun 25, 2018

Did you try to run those examples from where they were installed? Or you copy and pasted it to the console?

@mi-hol
Copy link
Author

mi-hol commented Jun 25, 2018

I've copy and pasted it to the console

@dfinke
Copy link
Owner

dfinke commented Jun 25, 2018

Yeah, those examples are intended to be run from that location. I use it for testing. Let me think through a better approach so they can be used in both scenarios.

@mi-hol
Copy link
Author

mi-hol commented Jun 26, 2018

@dfinke by using a custom module path, both scenarios should work with the proposed fix.

Set PSModulePath for testing a new unreleased version:
set PSModulePath=<new_release_dir>;$PSModulePath

@mi-hol
Copy link
Author

mi-hol commented Jul 21, 2018

@dfinke did you get a chance to try my proposed solution?
The related PR ´Fix import-module syntax in samples #367´was closed without a comment

@dfinke
Copy link
Owner

dfinke commented Jul 21, 2018

Check out the examples, I went with a different approach

@mi-hol
Copy link
Author

mi-hol commented Aug 4, 2018

@dfinke thanks for fixing.
The example worked after I installed LibreOffice.

Due to '$ExcelParams = @{ ... Show = $false' there is a dependency on having Excel or a compatible program installed to run the examples successfully.
For a beginner this is somehow counter intuitive as the purpose is:
'This PowerShell Module allows you to read and write Excel files without installing Microsoft Excel on your system'.
Maybe this fact should be noted in the example or the code changed to avoid the dependency?

example in LibreOffice German:
importexcel

@mi-hol
Copy link
Author

mi-hol commented Aug 4, 2018

the simple code that should also work on non-Windows OS using PowerShell Core 6.0 and later:

$outputFile = "test1.xlsx"
Remove-Item $outputFile -ErrorAction Ignore

$ExcelParams = @{
    Path              = $outputFile
    IncludePivotTable = $true
    PivotRows         = 'Company'
    PivotTableName    = 'MyTable'
    PivotData         = @{'Handles' = 'sum'}
    Show              = $false
}

Get-Process | Select-Object Company, Handles |
    Export-Excel @ExcelParams 
Get-ChildItem $outputFile

@dfinke
Copy link
Owner

dfinke commented Aug 4, 2018

Yup, the -Show requires Excel. This module generates an xlsx when it runs on PS Core?

@mi-hol
Copy link
Author

mi-hol commented Aug 5, 2018

Using PS core 6.0.3 on Windows, yes it does work :)
Will try on Linux RHEL 7.x later this week.
With PS core 6.1 preview 4 running on WindowsSubsystem for Linux (WSL) and Ubuntu 18.04 it failed so far. But this is more likely due to the previews status of PS as it fails with the module MergeCsv too, I had MergeCsv already working on earlier versions.

error encountered:

PS /root> Import-Module -Name importexcel
Import-Module : The specified module 'importexcel' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module -Name importexcel
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (importexcel:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

@mi-hol
Copy link
Author

mi-hol commented Aug 5, 2018

PowerShell/PowerShell#7451

@mi-hol
Copy link
Author

mi-hol commented Aug 5, 2018

@dfinke are you considering to deal with my comment :
"having Excel.. installed to run the examples successfully ... is somehow counter intuitive "?

I foresee many use cases to create xlsx on LINUX machines.

@dfinke
Copy link
Owner

dfinke commented Aug 5, 2018

When EPPlus is fully xplat, these will be addressed

@mi-hol
Copy link
Author

mi-hol commented Aug 5, 2018

For me as a none native speaker "xplat" didn´t ring a bell initially
Is seems to mean cross platform, so the work described in issue #150
Did I get this right?

@eweilnau
Copy link

eweilnau commented Aug 6, 2018

xplat does mean cross platform. I am pretty sure that the use of 'x' for 'cross' comes from the UK name for tic tac toe (i.e. noughts and crosses).

@mi-hol
Copy link
Author

mi-hol commented Aug 7, 2018

@dfinke EPPlus.Core works under WSL already.
nuget install EPPlus.Core did the trick
Guess the missing piece is adding this as a dependency to the ImportExcel package

@dfinke
Copy link
Owner

dfinke commented Aug 7, 2018

I tried the 4.5.x dll nuget with import Excel. Did the import-module and it failed on System.Drawing

@mi-hol
Copy link
Author

mi-hol commented Aug 8, 2018

I understand you are en expert but with the very brief comments I fail to understand the difference between your failing and my working approach.
I'd love to help and move this forward, but that requires more detailed information and maybe even a shared 'workspace' to collaborate.
As I understand it before a simple 'Import-Module -Name importexcel' can actually work, changes to the module definition are required.

@mi-hol
Copy link
Author

mi-hol commented Aug 8, 2018

I got "nuget install EPPlus.Core" working following the fix to update to latest mono version
JanKallman/EPPlus#224 (comment)

@dfinke
Copy link
Owner

dfinke commented Aug 8, 2018

I was able to run the module on my Linux VM in Azure and on my local machine PS Core 6.

Until PS Core is GA and it can run in Appveyor with continuous integration and more tests. Use it at your own risk.

https://ci.appveyor.com/project/dfinke/importexcel/build/1.0.171

@dfinke dfinke closed this as completed May 2, 2020
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

Successfully merging a pull request may close this issue.

3 participants