Merge remote-tracking branch 'upstream/master'

This commit is contained in:
jhoneill
2018-07-02 09:18:44 +01:00
29 changed files with 536 additions and 376 deletions

1
.gitignore vendored
View File

@@ -55,4 +55,3 @@ test.xlsx
testCCFMT.ps1
testHide.ps1
ImportExcel.zip
*.xlsx

26
.vscode/spellright.dict vendored Normal file
View File

@@ -0,0 +1,26 @@
databar
appveyor
SqlDataToExcel
xlsm
jameseholt
params
robinmalik
scriptblock
headsphere
xelsirko
importexcel
Mihalicz
idx
Möller
redoz
dir
pivotables
WorkSheetname
Lachance-Guillemette
ints
pscookiemonster
ps
pwd
Nuget
EPPLus
intellisense

7
DoTests.ps1 Normal file
View File

@@ -0,0 +1,7 @@
$PSVersionTable.PSVersion
if ((Get-Module -ListAvailable pester) -eq $null) {
Install-Module -Name Pester -Repository PSGallery -Force
}
Invoke-Pester -Script $PSScriptRoot\__tests__

BIN
Examples/Charts/Tools.xlsx Normal file

Binary file not shown.

View File

@@ -0,0 +1,21 @@
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
$excel = Get-Process |
Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS |
Export-Excel -Path .\test.xlsx -ClearSheet -WorkSheetname "Processes" -PassThru
$sheet = $excel.Workbook.Worksheets["Processes"]
$sheet.Column(1) | Set-Format -Bold -AutoFit
$sheet.Column(2) | Set-Format -Width 29 -WrapText
$sheet.Column(3) | Set-Format -HorizontalAlignment Right -NFormat "#,###"
Set-Format -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###"
Set-Format -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold
Set-Format -Address $sheet.Row(1) -Bold -HorizontalAlignment Center
Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red
Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red
foreach ($c in 5..9) {Set-Format -Address $sheet.Column($c) -AutoFit }
Export-Excel -ExcelPackage $excel -WorkSheetname "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show

Binary file not shown.

View File

@@ -0,0 +1,7 @@
Import-Module ..\..\ImportExcel.psd1 -Force
ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path ".\Movies.xlsx" -ConvertEmptyStringsToNull
''
'# UseMSSQLSyntax'
ConvertFrom-ExcelToSQLInsert -UseMSSQLSyntax -TableName "Movies" -Path ".\Movies.xlsx" -ConvertEmptyStringsToNull

Binary file not shown.

BIN
Examples/Fibonacci/fib.xlsx Normal file

Binary file not shown.

View File

@@ -0,0 +1,38 @@
if(!(gcm ig -ErrorAction SilentlyContinue)) {
"Use ``Install-Module NameIT`` to get the needed module from the gallery to support running this script"
return
}
$sign=@{sign=echo + -}
$location=@{location=echo Atlanta Newark Washington Chicago Philadelphia Houston Phoneix}
$(1..6 | % {
$from=$to=""
while($from -eq $to) {
$from=ig "[location]" -CustomData $location
$to=ig "[location]" -CustomData $location
}
[double]$a=ig "########"
[double]$b=ig ".####"
[double]$c=ig "#######"
[double]$d=ig "[sign].##" -CustomData $sign
[double]$e=ig "###"
[double]$f=ig "[sign]##" -CustomData $sign
#"{0},{1},{2},{3},{4},{5},{6},{7}" -f $from, $to, $a, $b, $c, $d, $e, $f
[PSCustomObject][Ordered]@{
From=$from
To=$to
RDollars=$a
RPercent=$b
MDollars=$c
MPercent=$d
Revenue=$e
Margin=$f
}
} | ConvertTo-Csv -NoTypeInformation) -replace '"','' # | Export-Excel

View File

@@ -1,9 +1,9 @@
ColumnChart -Title "Central Limit Theorem" ($(
for ($i = 1; $i -le 500; $i++) {
$s=0
for ($j = 1; $j -le 100; $j++){
$s+=Get-Random -Minimum 0 -Maximum 2
ColumnChart -Title "Central Limit Theorem" -NoLegend ($(
for ($i = 1; $i -le 500; $i++) {
$s = 0
for ($j = 1; $j -le 100; $j++) {
$s += Get-Random -Minimum 0 -Maximum 2
}
$s
}
$s
}
) | Sort | Group | select Count, Name)
) | Sort-Object | Group-Object | Select-Object Count, Name)

Binary file not shown.

View File

@@ -0,0 +1,15 @@
Import-Module ..\..\ImportExcel.psd1 -Force
Remove-Item .\test1.xlsx -ErrorAction Ignore
$ExcelParams = @{
Path = ".\test1.xlsx"
IncludePivotTable = $true
PivotRows = 'Company'
PivotTableName = 'MyTable'
PivotData = @{'Handles' = 'sum'}
Show = $true
}
Get-Process | Select-Object Company, Handles |
Export-Excel @ExcelParams

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
Remove-Item .\testFormula.xlsx -ErrorAction Ignore
@"
id,item,units,cost
12001,Nails,37,3.99
12002,Hammer,5,12.10
12003,Saw,12,15.37
12010,Drill,20,8
12011,Crowbar,7,23.48
"@ | ConvertFrom-Csv |
Add-Member -PassThru -MemberType NoteProperty -Name Total -Value "=units*cost" |
Export-Excel -Path .\testFormula.xlsx -Show -AutoSize -AutoNameRange

View File

@@ -312,6 +312,8 @@
It then uses the package object to apply formatting, and then saves the workbook and disposes of the object before loading the document in Excel.
.EXAMPLE
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
$excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | Export-Excel -Path .\test.xlsx -ClearSheet -WorkSheetname "Processes" -PassThru
$sheet = $excel.Workbook.Worksheets["Processes"]
$sheet.Column(1) | Set-Format -Bold -AutoFit
@@ -322,7 +324,7 @@
Set-Format -Address $sheet.Row(1) -Bold -HorizontalAlignment Center
Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red
Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red
foreach ($c in 5..9) {Set-Format $sheet.Column($c) -AutoFit }
foreach ($c in 5..9) {Set-Format -Address $sheet.Column($c) -AutoFit }
Export-Excel -ExcelPackage $excel -WorkSheetname "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show
This a more sophisticated version of the previous example showing different ways of using Set-Format, and also adding conditional formatting.

View File

@@ -4,7 +4,7 @@
RootModule = 'ImportExcel.psm1'
# Version number of this module.
ModuleVersion = '4.0.14'
ModuleVersion = '5.0.1'
# ID used to uniquely identify this module
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'

View File

@@ -44,6 +44,7 @@ Begin {
'Import-Html.ps1',
'InferData.ps1',
'Invoke-Sum.ps1',
'Merge-Worksheet.ps1',
'New-ConditionalFormattingIconSet.ps1',
'New-ConditionalText.ps1',
'New-ExcelChart.ps1',

View File

@@ -1,4 +1,4 @@
Import-Module .\ImportExcel.psd1 -Force
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
$xlFile = ".\testSQL.xlsx"

View File

@@ -1,8 +1,8 @@
#Requires -Modules Pester
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module $here -Force -Verbose
# $here = Split-Path -Parent $MyInvocation.MyCommand.Path
# Import-Module $here -Force -Verbose
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
if (Get-process -Name Excel,xlim -ErrorAction SilentlyContinue) { Write-Warning -Message "You need to close Excel before running the tests." ; return}
Describe ExportExcel {
@@ -29,7 +29,7 @@ Describe ExportExcel {
#This is a test of using it with -KillExcel
#TODO Need to test opening pre-existing file with no -create switch (and graceful failure when file does not exist) somewhere else
$Excel = Open-ExcelPackage -Path $path -KillExcel
it "Killed Excel when Open-Excelpackage was told to " {
it -Skip "Killed Excel when Open-Excelpackage was told to " {
Get-process -Name Excel,xlim -ErrorAction SilentlyContinue | should benullorempty
}

Binary file not shown.

View File

@@ -0,0 +1,32 @@
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1
Describe "Tests" {
BeforeAll {
$data = $null
$timer = Measure-Command {
$data = Import-Excel $PSScriptRoot\Simple.xlsx
}
}
It "Should have two items" {
$data.count | Should be 2
}
It "Should have items a and b" {
$data[0].p1 | Should be "a"
$data[1].p1 | Should be "b"
}
It "Should read fast < 1000 milliseconds" {
$timer.TotalMilliseconds | should BeLessThan 1000
}
It "Should read larger xlsx, 4k rows 1 col < 2000 milliseconds" {
$timer = Measure-Command {
$null = Import-Excel $PSScriptRoot\LargerFile.xlsx
}
$timer.TotalMilliseconds | should BeLessThan 2000
}
}

Binary file not shown.

BIN
appveyor.yml Normal file

Binary file not shown.

BIN
dashboard.xlsx Normal file

Binary file not shown.

BIN
test1.xlsx Normal file

Binary file not shown.

BIN
testTable.xlsx Normal file

Binary file not shown.