ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

import-module syntax error in 3 examples

Open mi-hol opened this issue 8 years ago • 21 comments

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 avatar Jun 25 '18 17:06 mi-hol

same issue is present in 2 more files:

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

mi-hol avatar Jun 25 '18 17:06 mi-hol

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

dfinke avatar Jun 25 '18 19:06 dfinke

I've copy and pasted it to the console

mi-hol avatar Jun 25 '18 19:06 mi-hol

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.

dfinke avatar Jun 25 '18 20:06 dfinke

@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 avatar Jun 26 '18 07:06 mi-hol

@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

mi-hol avatar Jul 21 '18 10:07 mi-hol

Check out the examples, I went with a different approach

dfinke avatar Jul 21 '18 11:07 dfinke

@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 avatar Aug 04 '18 16:08 mi-hol

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

mi-hol avatar Aug 04 '18 17:08 mi-hol

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

dfinke avatar Aug 04 '18 20:08 dfinke

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 avatar Aug 05 '18 10:08 mi-hol

https://github.com/PowerShell/PowerShell/issues/7451

mi-hol avatar Aug 05 '18 11:08 mi-hol

@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.

mi-hol avatar Aug 05 '18 12:08 mi-hol

When EPPlus is fully xplat, these will be addressed

dfinke avatar Aug 05 '18 13:08 dfinke

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?

mi-hol avatar Aug 05 '18 13:08 mi-hol

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).

eweilnau avatar Aug 06 '18 14:08 eweilnau

@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

mi-hol avatar Aug 07 '18 17:08 mi-hol

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

dfinke avatar Aug 07 '18 17:08 dfinke

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 avatar Aug 08 '18 16:08 mi-hol

I got "nuget install EPPlus.Core" working following the fix to update to latest mono version https://github.com/JanKallman/EPPlus/issues/224#issuecomment-411119474

mi-hol avatar Aug 08 '18 19:08 mi-hol