import-module syntax error in 3 examples
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 :)
same issue is present in 2 more files:
Examples/CustomReporting/CustomReport.ps1 Examples/ExcelToSQLInsert/DemoSQLInsert.ps1
Did you try to run those examples from where they were installed? Or you copy and pasted it to the console?
I've copy and pasted it to the console
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 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
@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
Check out the examples, I went with a different approach
@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:
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
Yup, the -Show requires Excel. This module generates an xlsx when it runs on PS Core?
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
https://github.com/PowerShell/PowerShell/issues/7451
@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.
When EPPlus is fully xplat, these will be addressed
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?
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).
@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
I tried the 4.5.x dll nuget with import Excel. Did the import-module and it failed on System.Drawing
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.
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