mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -55,4 +55,3 @@ test.xlsx
|
||||
testCCFMT.ps1
|
||||
testHide.ps1
|
||||
ImportExcel.zip
|
||||
*.xlsx
|
||||
|
||||
26
.vscode/spellright.dict
vendored
Normal file
26
.vscode/spellright.dict
vendored
Normal 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
7
DoTests.ps1
Normal 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
BIN
Examples/Charts/Tools.xlsx
Normal file
Binary file not shown.
21
Examples/ConditionalFormatting/Databar.ps1
Normal file
21
Examples/ConditionalFormatting/Databar.ps1
Normal 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
|
||||
BIN
Examples/CustomReporting/dashboard.xlsx
Normal file
BIN
Examples/CustomReporting/dashboard.xlsx
Normal file
Binary file not shown.
7
Examples/ExcelToSQLInsert/DemoSQLInsert.ps1
Normal file
7
Examples/ExcelToSQLInsert/DemoSQLInsert.ps1
Normal 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
|
||||
BIN
Examples/ExcelToSQLInsert/Movies.xlsx
Normal file
BIN
Examples/ExcelToSQLInsert/Movies.xlsx
Normal file
Binary file not shown.
BIN
Examples/Fibonacci/fib.xlsx
Normal file
BIN
Examples/Fibonacci/fib.xlsx
Normal file
Binary file not shown.
38
Examples/GenerateData/GenDataForCustomReport.ps1
Normal file
38
Examples/GenerateData/GenDataForCustomReport.ps1
Normal 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
|
||||
@@ -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)
|
||||
BIN
Examples/MultiplierTable/MultiplierTable.xlsx
Normal file
BIN
Examples/MultiplierTable/MultiplierTable.xlsx
Normal file
Binary file not shown.
15
Examples/PivotTable/PivotTableWithName.ps1
Normal file
15
Examples/PivotTable/PivotTableWithName.ps1
Normal 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
|
||||
BIN
Examples/PivotTableFilters/dashboard.xlsx
Normal file
BIN
Examples/PivotTableFilters/dashboard.xlsx
Normal file
Binary file not shown.
BIN
Examples/PivotTableFilters/testPivot.xlsx
Normal file
BIN
Examples/PivotTableFilters/testPivot.xlsx
Normal file
Binary file not shown.
12
Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1
Normal file
12
Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1
Normal 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
|
||||
@@ -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.
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Import-Module .\ImportExcel.psd1 -Force
|
||||
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
|
||||
|
||||
$xlFile = ".\testSQL.xlsx"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
BIN
__tests__/ImportExcelTests/LargerFile.xlsx
Normal file
BIN
__tests__/ImportExcelTests/LargerFile.xlsx
Normal file
Binary file not shown.
32
__tests__/ImportExcelTests/Simple.tests.ps1
Normal file
32
__tests__/ImportExcelTests/Simple.tests.ps1
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
BIN
__tests__/ImportExcelTests/Simple.xlsx
Normal file
BIN
__tests__/ImportExcelTests/Simple.xlsx
Normal file
Binary file not shown.
BIN
appveyor.yml
Normal file
BIN
appveyor.yml
Normal file
Binary file not shown.
BIN
dashboard.xlsx
Normal file
BIN
dashboard.xlsx
Normal file
Binary file not shown.
BIN
test1.xlsx
Normal file
BIN
test1.xlsx
Normal file
Binary file not shown.
BIN
testTable.xlsx
Normal file
BIN
testTable.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user