Skip to content

Commit

Permalink
Add a check for the ImportExcel module, if the AsExcel is used
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinke committed Oct 28, 2019
1 parent 95e2863 commit 12a90cb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion InvokePowerShellNotebook.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ function Invoke-PowerShellNotebook {
Write-Progress -Activity "Executing PowerShell code block - [$(Get-Date)]" -Status (-join $targetCode) -PercentComplete (($idx + 1) / $codeBlockCount * 100)

if ($AsExcel) {
if (!(Get-Module -ListAvailable ImportExcel -ErrorAction SilentlyContinue)) {
throw "This feature requires the ImportExcel PowerShell module. Use 'Install-Module -Name ImportExcel' to get it from the PS Gallery."
}

if ($idx -eq 0) {
$notebookFileName = Split-Path $NoteBookFullName -Leaf
$xlFileName = $notebookFileName -replace ".ipynb", ".xlsx"

$xlfile = "{0}\{1}" -f $pwd.Path, $xlFileName
$xlfile = " { 0 }\ { 1 }" -f $pwd.Path, $xlFileName
Remove-Item $xlfile -ErrorAction SilentlyContinue
}

Expand Down

0 comments on commit 12a90cb

Please sign in to comment.