diff --git a/.vscode/spellright.dict b/.vscode/spellright.dict index 6b51374..58b8ceb 100644 --- a/.vscode/spellright.dict +++ b/.vscode/spellright.dict @@ -24,3 +24,4 @@ pwd Nuget EPPLus intellisense +PivtoTableName diff --git a/__tests__/Compare-WorkSheet.tests.ps1 b/Compare-WorkSheet.tests.ps1 similarity index 100% rename from __tests__/Compare-WorkSheet.tests.ps1 rename to Compare-WorkSheet.tests.ps1 diff --git a/Examples/ConvertFrom/ConvertFrom.ps1 b/Examples/ConvertFrom/ConvertFrom.ps1 index d7451c3..0aeac85 100644 --- a/Examples/ConvertFrom/ConvertFrom.ps1 +++ b/Examples/ConvertFrom/ConvertFrom.ps1 @@ -1,3 +1,4 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} ConvertFrom-ExcelToSQLInsert People .\testSQLGen.xlsx diff --git a/Examples/CustomReporting/CustomReport.ps1 b/Examples/CustomReporting/CustomReport.ps1 index 3aa3c6d..919e784 100644 --- a/Examples/CustomReporting/CustomReport.ps1 +++ b/Examples/CustomReporting/CustomReport.ps1 @@ -1,4 +1,4 @@ -Import-Module ..\..\ImportExcel.psd1 -Force +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} $f = ".\dashboard.xlsx" Remove-Item $f -ErrorAction Ignore diff --git a/Examples/CustomReporting/dashboard.xlsx b/Examples/CustomReporting/dashboard.xlsx index 3da8e01..c2afb01 100644 Binary files a/Examples/CustomReporting/dashboard.xlsx and b/Examples/CustomReporting/dashboard.xlsx differ diff --git a/Examples/ExcelToSQLInsert/DemoSQLInsert.ps1 b/Examples/ExcelToSQLInsert/DemoSQLInsert.ps1 index ef63a54..9825e1c 100644 --- a/Examples/ExcelToSQLInsert/DemoSQLInsert.ps1 +++ b/Examples/ExcelToSQLInsert/DemoSQLInsert.ps1 @@ -1,5 +1,4 @@ -Import-Module ..\..\ImportExcel.psd1 -Force - +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path ".\Movies.xlsx" -ConvertEmptyStringsToNull '' diff --git a/Examples/Fibonacci/ShowFibonacci.ps1 b/Examples/Fibonacci/ShowFibonacci.ps1 index d242b85..54bc2d1 100644 --- a/Examples/Fibonacci/ShowFibonacci.ps1 +++ b/Examples/Fibonacci/ShowFibonacci.ps1 @@ -1,15 +1,17 @@ param ($fibonacciDigits=10) +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "fib.xlsx" -rm "fib.xlsx" -ErrorAction Ignore +Remove-Item "fib.xlsx" -ErrorAction Ignore $( New-PSItem 0 New-PSItem 1 - + ( 2..$fibonacciDigits | - ForEach { + ForEach-Object { New-PSItem ('=a{0}+a{1}' -f ($_+1),$_) } ) diff --git a/Examples/Fibonacci/fib.xlsx b/Examples/Fibonacci/fib.xlsx index b4abac9..431ef10 100644 Binary files a/Examples/Fibonacci/fib.xlsx and b/Examples/Fibonacci/fib.xlsx differ diff --git a/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 b/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 index f158277..9fb2b21 100644 --- a/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 +++ b/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 @@ -1,12 +1,16 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +$xlfile = "$env:temp\testFmt.xlsx" + Get-Process | - Select-Object Company,Handles,PM, NPM| + Select-Object Company,Handles,PM, NPM| Export-Excel $xlfile -Show -AutoSize -CellStyleSB { param( $workSheet, $totalRows, $lastColumn ) - + Set-CellStyle $workSheet 1 $LastColumn Solid Cyan foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 0})) { diff --git a/Examples/FormatCellStyles/PassInScriptBlock.ps1 b/Examples/FormatCellStyles/PassInScriptBlock.ps1 index 044fff9..ac9e0a2 100644 --- a/Examples/FormatCellStyles/PassInScriptBlock.ps1 +++ b/Examples/FormatCellStyles/PassInScriptBlock.ps1 @@ -1,9 +1,14 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +$xlfile = "$env:temp\testFmt.xlsx" +Remove-Item $xlfile -ErrorAction Ignore + $RandomStyle = { param( $workSheet, $totalRows, $lastColumn - ) + ) 2..$totalRows | ForEach-Object{ Set-CellStyle $workSheet $_ $LastColumn Solid (Write-Output LightGreen Gray Red|Get-Random) @@ -11,5 +16,5 @@ $RandomStyle = { } Get-Process | - Select-Object Company,Handles,PM, NPM| + Select-Object Company,Handles,PM, NPM| Export-Excel $xlfile -Show -AutoSize -CellStyleSB $RandomStyle diff --git a/Examples/HyperLinks/Hyperlinks.ps1 b/Examples/HyperLinks/Hyperlinks.ps1 index 2356698..6e5c2be 100644 --- a/Examples/HyperLinks/Hyperlinks.ps1 +++ b/Examples/HyperLinks/Hyperlinks.ps1 @@ -1,7 +1,8 @@ -#$( -# New-PSItem 'Every Man a King' http://orisonswettmarden.wwwhubs.com/ccount/click.php?id=2 -# New-PSItem 'Be Good to Yourself' http://orisonswettmarden.wwwhubs.com/ccount/click.php?id=3 -# New-PSItem 'Character : The Grandest Thing in the World' http://orisonswettmarden.wwwhubs.com/ccount/click.php?id=4 -# New-PSItem 'The Conquest of Worry' http://orisonswettmarden.wwwhubs.com/ccount/click.php?id=5 -# New-PSItem 'Success Nuggets' http://orisonswettmarden.wwwhubs.com/ccount/click.php?id=6 -#) | Export-Excel hyperlinks.xlsx -Show -AutoSize \ No newline at end of file +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +@" +site,link +google,http://www.google.com +stackoverflow,http://stackoverflow.com +microsoft,http://microsoft.com +"@ | ConvertFrom-Csv | Export-Excel diff --git a/Examples/ImportHtml/DemoGraphics.ps1 b/Examples/ImportHtml/DemoGraphics.ps1 index 011e104..68c8868 100644 --- a/Examples/ImportHtml/DemoGraphics.ps1 +++ b/Examples/ImportHtml/DemoGraphics.ps1 @@ -1,2 +1,4 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + Import-Html "http://en.wikipedia.org/wiki/Demographics_of_India" 4 \ No newline at end of file diff --git a/Examples/ImportHtml/PeriodicElements.ps1 b/Examples/ImportHtml/PeriodicElements.ps1 index 50d7cbe..d4038a4 100644 --- a/Examples/ImportHtml/PeriodicElements.ps1 +++ b/Examples/ImportHtml/PeriodicElements.ps1 @@ -1 +1,3 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + Import-Html "http://www.science.co.il/PTelements.asp" 1 \ No newline at end of file diff --git a/Examples/ImportHtml/StarTrek.ps1 b/Examples/ImportHtml/StarTrek.ps1 index a5ca93d..17fd975 100644 --- a/Examples/ImportHtml/StarTrek.ps1 +++ b/Examples/ImportHtml/StarTrek.ps1 @@ -1 +1,3 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + Import-Html "https://en.wikipedia.org/wiki/List_of_Star_Trek:_The_Original_Series_episodes" 2 \ No newline at end of file diff --git a/Examples/JoinWorksheet/EastSales.csv b/Examples/JoinWorksheet/EastSales.csv new file mode 100644 index 0000000..016be35 --- /dev/null +++ b/Examples/JoinWorksheet/EastSales.csv @@ -0,0 +1,6 @@ +"Region","Item","UnitSold","UnitCost" +"East","Banana","38","0.26" +"East","Kale","71","0.69" +"East","Apple","35","0.55" +"East","Potato","48","0.48" +"East","Kale","41","0.74" \ No newline at end of file diff --git a/Examples/JoinWorksheet/JoinSalesData.ps1 b/Examples/JoinWorksheet/JoinSalesData.ps1 new file mode 100644 index 0000000..a094ffd --- /dev/null +++ b/Examples/JoinWorksheet/JoinSalesData.ps1 @@ -0,0 +1,22 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +$xlfile = "$env:temp\AllSales.xlsx" + +Remove-Item $xlfile -ErrorAction Ignore + +$params = @{ + AutoSize = $true + AutoFilter = $true + AutoNameRange = $true + ExcelChartDefinition = New-ExcelChartDefinition -XRange Item -YRange UnitSold -Title 'Units Sold' + Path = $xlfile +} + +Import-Csv $PSScriptRoot\NorthSales.csv | Export-Excel -WorkSheetname North @params +Import-Csv $PSScriptRoot\EastSales.csv | Export-Excel -WorkSheetname East @params +Import-Csv $PSScriptRoot\SouthSales.csv | Export-Excel -WorkSheetname South @params +Import-Csv $PSScriptRoot\WestSales.csv | Export-Excel -WorkSheetname West @params + +$params.Remove("AutoNameRange") +$params.Remove("ExcelChartDefinition") +Join-Worksheet -WorkSheetName AllSales -Show @params \ No newline at end of file diff --git a/Examples/JoinWorksheet/NorthSales.csv b/Examples/JoinWorksheet/NorthSales.csv new file mode 100644 index 0000000..361c9b2 --- /dev/null +++ b/Examples/JoinWorksheet/NorthSales.csv @@ -0,0 +1,5 @@ +"Region","Item","UnitSold","UnitCost" +"North","Apple","40","0.68" +"North","Kale","55","0.35" +"North","Banana","33","0.31" +"North","Pear","29","0.74" \ No newline at end of file diff --git a/Examples/JoinWorksheet/SouthSales.csv b/Examples/JoinWorksheet/SouthSales.csv new file mode 100644 index 0000000..a268248 --- /dev/null +++ b/Examples/JoinWorksheet/SouthSales.csv @@ -0,0 +1,6 @@ +"Region","Item","UnitSold","UnitCost" +"South","Banana","54","0.46" +"South","Pear","39","0.44" +"South","Potato","33","0.46" +"South","Banana","49","0.31" +"South","Apple","38","0.59" \ No newline at end of file diff --git a/Examples/JoinWorksheet/WestSales.csv b/Examples/JoinWorksheet/WestSales.csv new file mode 100644 index 0000000..26770ee --- /dev/null +++ b/Examples/JoinWorksheet/WestSales.csv @@ -0,0 +1,12 @@ +"Region","Item","UnitSold","UnitCost" +"West","Banana","74","0.56" +"West","Apple","26","0.7" +"West","Banana","59","0.49" +"West","Potato","56","0.62" +"West","Banana","60","0.64" +"West","Pear","32","0.29" +"West","Apple","73","0.26" +"West","Banana","49","0.59" +"West","Pear","65","0.35" +"West","Apple","60","0.34" +"West","Kale","67","0.38" \ No newline at end of file diff --git a/Examples/JustCharts/CentralLimitTheorem.ps1 b/Examples/JustCharts/CentralLimitTheorem.ps1 index 7696d37..1d59d3d 100644 --- a/Examples/JustCharts/CentralLimitTheorem.ps1 +++ b/Examples/JustCharts/CentralLimitTheorem.ps1 @@ -1,4 +1,6 @@ -ColumnChart -Title "Central Limit Theorem" -NoLegend ($( +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +ColumnChart -Title "Central Limit Theorem" -NoLegend ($( for ($i = 1; $i -le 500; $i++) { $s = 0 for ($j = 1; $j -le 100; $j++) { diff --git a/Examples/JustCharts/PieChartHandles.ps1 b/Examples/JustCharts/PieChartHandles.ps1 index 357eee9..7103275 100644 --- a/Examples/JustCharts/PieChartHandles.ps1 +++ b/Examples/JustCharts/PieChartHandles.ps1 @@ -2,5 +2,7 @@ # Sum up handles by company # Show the Pie Chart +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + PieChart -Title "Total Handles by Company" ` - (Invoke-Sum (Get-Process|Where company) company handles) + (Invoke-Sum (Get-Process | Where-Object company) company handles) diff --git a/Examples/JustCharts/PieChartPM.ps1 b/Examples/JustCharts/PieChartPM.ps1 index 3a911cf..68c404f 100644 --- a/Examples/JustCharts/PieChartPM.ps1 +++ b/Examples/JustCharts/PieChartPM.ps1 @@ -2,6 +2,8 @@ # Sum up PM by company # Show the Pie Chart -PieChart -Title "Total PM by Company" ` - (Invoke-Sum (Get-Process|Where company) company pm) +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +PieChart -Title "Total PM by Company" ` + (Invoke-Sum (Get-Process|Where-Object company) company pm) diff --git a/Examples/JustCharts/TryBarChart.ps1 b/Examples/JustCharts/TryBarChart.ps1 index 11fec69..57208de 100644 --- a/Examples/JustCharts/TryBarChart.ps1 +++ b/Examples/JustCharts/TryBarChart.ps1 @@ -1 +1,3 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + BarChart (.\TargetData.ps1) "A BarChart" \ No newline at end of file diff --git a/Examples/JustCharts/TryColumnChart.ps1 b/Examples/JustCharts/TryColumnChart.ps1 index a184db4..d4bd515 100644 --- a/Examples/JustCharts/TryColumnChart.ps1 +++ b/Examples/JustCharts/TryColumnChart.ps1 @@ -1 +1,3 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + ColumnChart (.\TargetData.ps1) "A ColumnChart" diff --git a/Examples/JustCharts/TryPieChart.ps1 b/Examples/JustCharts/TryPieChart.ps1 index 236bc96..09ccaad 100644 --- a/Examples/JustCharts/TryPieChart.ps1 +++ b/Examples/JustCharts/TryPieChart.ps1 @@ -1 +1,3 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + PieChart (.\TargetData.ps1) "A PieChart" \ No newline at end of file diff --git a/Examples/Nasa/FireBalls.ps1 b/Examples/Nasa/FireBalls.ps1 index b0582c4..cec1554 100644 --- a/Examples/Nasa/FireBalls.ps1 +++ b/Examples/Nasa/FireBalls.ps1 @@ -1,3 +1,5 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $header = echo ` 'Date/Time - Peak Brightness (UT)' ` 'Latitude (Deg)' ` @@ -12,8 +14,8 @@ $header = echo ` $splat=@{ url='http://neo.jpl.nasa.gov/fireballs/' - index=5 - Header=$header + index=5 + Header=$header FirstDataRow=1 } diff --git a/Examples/NumberFormat/ColorizeNumbers.ps1 b/Examples/NumberFormat/ColorizeNumbers.ps1 index 7d80f52..18a2dc1 100644 --- a/Examples/NumberFormat/ColorizeNumbers.ps1 +++ b/Examples/NumberFormat/ColorizeNumbers.ps1 @@ -1,6 +1,8 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore $data = $( New-PSItem 100 -100 diff --git a/Examples/NumberFormat/CurrencyFormat.ps1 b/Examples/NumberFormat/CurrencyFormat.ps1 index 1d608ce..e7c327a 100644 --- a/Examples/NumberFormat/CurrencyFormat.ps1 +++ b/Examples/NumberFormat/CurrencyFormat.ps1 @@ -1,6 +1,8 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore $data = $( New-PSItem 100 -100 diff --git a/Examples/NumberFormat/PercentagFormat.ps1 b/Examples/NumberFormat/PercentagFormat.ps1 index 95b156b..b2e50ed 100644 --- a/Examples/NumberFormat/PercentagFormat.ps1 +++ b/Examples/NumberFormat/PercentagFormat.ps1 @@ -1,6 +1,8 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore $data = $( New-PSItem 1 diff --git a/Examples/NumberFormat/PosNegNumbers.ps1 b/Examples/NumberFormat/PosNegNumbers.ps1 index 43fbf51..5160822 100644 --- a/Examples/NumberFormat/PosNegNumbers.ps1 +++ b/Examples/NumberFormat/PosNegNumbers.ps1 @@ -1,6 +1,8 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore $data = $( New-PSItem 100 -100 diff --git a/Examples/NumberFormat/Win32LogicalDisk.ps1 b/Examples/NumberFormat/Win32LogicalDisk.ps1 index 6dc590e..fc981dc 100644 --- a/Examples/NumberFormat/Win32LogicalDisk.ps1 +++ b/Examples/NumberFormat/Win32LogicalDisk.ps1 @@ -1,7 +1,9 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore -Get-CimInstance win32_logicaldisk -filter "drivetype=3" | - Select DeviceID,Volumename,Size,Freespace | +Get-CimInstance win32_logicaldisk -filter "drivetype=3" | + Select-Object DeviceID,Volumename,Size,Freespace | Export-Excel -Path $file -Show -AutoSize -NumberFormat "0" \ No newline at end of file diff --git a/Examples/NumberFormat/Win32LogicalDiskFormatted.ps1 b/Examples/NumberFormat/Win32LogicalDiskFormatted.ps1 index 4e3b3c1..671f979 100644 --- a/Examples/NumberFormat/Win32LogicalDiskFormatted.ps1 +++ b/Examples/NumberFormat/Win32LogicalDiskFormatted.ps1 @@ -1,7 +1,9 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "disks.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore -Get-CimInstance win32_logicaldisk -filter "drivetype=3" | - Select DeviceID,Volumename,Size,Freespace | +Get-CimInstance win32_logicaldisk -filter "drivetype=3" | + Select-Object DeviceID,Volumename,Size,Freespace | Export-Excel -Path $file -Show -AutoSize \ No newline at end of file diff --git a/Examples/NumberFormat/disks.xlsx b/Examples/NumberFormat/disks.xlsx new file mode 100644 index 0000000..79baae1 Binary files /dev/null and b/Examples/NumberFormat/disks.xlsx differ diff --git a/Examples/PassThru/TryPassThru.ps1 b/Examples/PassThru/TryPassThru.ps1 index 0a7591a..c33060f 100644 --- a/Examples/PassThru/TryPassThru.ps1 +++ b/Examples/PassThru/TryPassThru.ps1 @@ -1,6 +1,8 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $file = "sales.xlsx" -rm $file -ErrorAction Ignore +Remove-Item $file -ErrorAction Ignore $xlPkg = Import-Csv .\sales.csv | Export-Excel $file -PassThru @@ -9,8 +11,8 @@ $ws = $xlPkg.Workbook.WorkSheets[1] $ws.Cells["E1"].Value = "TotalSold" $ws.Cells["F1"].Value = "Add 10%" -2..($ws.Dimension.Rows) | - ForEach { +2..($ws.Dimension.Rows) | + ForEach-Object { $ws.Cells["E$_"].Formula = "=C$_+D$_" $ws.Cells["F$_"].Formula = "=E$_+(10%*(C$_+D$_))" } diff --git a/Examples/PassThru/sales.xlsx b/Examples/PassThru/sales.xlsx new file mode 100644 index 0000000..ba69c5b Binary files /dev/null and b/Examples/PassThru/sales.xlsx differ diff --git a/Examples/PivotTable/PivotTableWithName.ps1 b/Examples/PivotTable/PivotTableWithName.ps1 index 7ffbee2..45524ea 100644 --- a/Examples/PivotTable/PivotTableWithName.ps1 +++ b/Examples/PivotTable/PivotTableWithName.ps1 @@ -1,4 +1,4 @@ -Import-Module ..\..\ImportExcel.psd1 -Force +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} Remove-Item .\test1.xlsx -ErrorAction Ignore diff --git a/Examples/PivotTable/test1.xlsx b/Examples/PivotTable/test1.xlsx new file mode 100644 index 0000000..182c72e Binary files /dev/null and b/Examples/PivotTable/test1.xlsx differ diff --git a/Examples/PivotTableFilters/testPivot.xlsx b/Examples/PivotTableFilters/testPivot.xlsx new file mode 100644 index 0000000..443beb0 Binary files /dev/null and b/Examples/PivotTableFilters/testPivot.xlsx differ diff --git a/Examples/PivotTableFilters/testPivotFilter.ps1 b/Examples/PivotTableFilters/testPivotFilter.ps1 index f63b349..b112690 100644 --- a/Examples/PivotTableFilters/testPivotFilter.ps1 +++ b/Examples/PivotTableFilters/testPivotFilter.ps1 @@ -1,4 +1,4 @@ -Import-Module ..\..\ImportExcel.psd1 -Force +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} $xlFile=".\testPivot.xlsx" Remove-Item $xlFile -ErrorAction Ignore diff --git a/Examples/Plot/PlotCos.ps1 b/Examples/Plot/PlotCos.ps1 index aec098a..e83980a 100644 --- a/Examples/Plot/PlotCos.ps1 +++ b/Examples/Plot/PlotCos.ps1 @@ -1,3 +1,5 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + $plt = New-Plot $plt.Plot((Get-Range 0 5 .02|%{[math]::Cos(2*[math]::pi*$_)})) $plt.SetChartSize(800,300) diff --git a/Examples/SQL+FillColumns+Pivot/Example.ps1 b/Examples/SQL+FillColumns+Pivot/Example.ps1 index 0c03515..9300f04 100644 --- a/Examples/SQL+FillColumns+Pivot/Example.ps1 +++ b/Examples/SQL+FillColumns+Pivot/Example.ps1 @@ -1,33 +1,33 @@ - Import-Module -name ImportExcel -Force -Verbose +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} $sql = @" - SELECT rootfile.baseName , rootfile.extension , Image.fileWidth AS width , image.fileHeight AS height , + SELECT rootfile.baseName , rootfile.extension , Image.fileWidth AS width , image.fileHeight AS height , metadata.dateDay , metadata.dateMonth , metadata.dateYear , Image.captureTime AS dateTaken, metadata.hasGPS , metadata.GPSLatitude , metadata.GPSLongitude , - metadata.focalLength , metadata.flashFired , metadata.ISOSpeedRating AS ISOSpeed, + metadata.focalLength , metadata.flashFired , metadata.ISOSpeedRating AS ISOSpeed, metadata.Aperture AS apertureValue , metadata.ShutterSpeed AS shutterSpeedValue, Image.bitdepth , image.colorLabels , - Camera.Value AS cameraModel , LensRef.value AS lensModel - FROM Adobe_images image - JOIN AgLibraryFile rootFile ON rootfile.id_local = image.rootFile - JOIN AgharvestedExifMetadata metadata ON image.id_local = metadata.image + Camera.Value AS cameraModel , LensRef.value AS lensModel + FROM Adobe_images image + JOIN AgLibraryFile rootFile ON rootfile.id_local = image.rootFile + JOIN AgharvestedExifMetadata metadata ON image.id_local = metadata.image LEFT JOIN AgInternedExifLens LensRef ON LensRef.id_Local = metadata.lensRef - LEFT JOIN AgInternedExifCameraModel Camera ON Camera.id_local = metadata.cameraModelRef -"@ -`` -#Sql Statement gets 20 columns of data from Adobe lightroom database -#Define a pivot table and chart for total pictures with each lens. + LEFT JOIN AgInternedExifCameraModel Camera ON Camera.id_local = metadata.cameraModelRef +"@ -$pt = @{"LensPivot" = @{ "PivotTableName" = "LensPivot"; +#Sql Statement gets 20 columns of data from Adobe lightroom database +#Define a pivot table and chart for total pictures with each lens. + +$pt = @{"LensPivot" = @{ "PivotTableName" = "LensPivot"; "SourceWorkSheet" = "Sheet1" ; "PivotRows" = "LensModel" ; "PivotData" = @{"basename" = "Count"} ; "IncludePivotChart" = $true ; "NoLegend" = $true ; - "ShowPercent" = $true ; + "ShowPercent" = $true ; "ChartType" = "Pie" ; "ChartTitle" = "Split by Lens" } -} +} #we want to add 3 columns, translate Apperture value and Shutter speed value into familar f/ and seconds notation, and use these and ISO to calculate EV level $Avalue = {"=IF(P$ROW>6.63,TEXT(ROUND(Sqrt(Power(2,O$ROW)),1),`"`"`"f/`"`"0.0`")," + @@ -37,52 +37,52 @@ $Svalue = {"=IF(P$ROW>2,TEXT(ROUND(POWER(2,P$ROW),0),`"`"`"1/`"`"0`"`"sec "TEXT(ROUND(1/POWER(2,P$ROW),2),`"0`"`"Sec`"`"`")))"} $evValue = {"=ROUND(P$Row+O$Row-(LOG(N$Row/100,2)),0)" } -#remove and recreate the file +#remove and recreate the file Remove-Item -Path "~\Documents\temp.xlsx" -ErrorAction SilentlyContinue -#Open a connection to the ODBC source "LR" (which points to the SQLLite DB for Lightroom), run the SQL query, and drop into Excel - in sheet1, autosizing columns. +#Open a connection to the ODBC source "LR" (which points to the SQLLite DB for Lightroom), run the SQL query, and drop into Excel - in sheet1, autosizing columns. $e = Send-SQLDataToExcel -Path "~\Documents\temp.xlsx" -WorkSheetname "Sheet1" -Connection "DSN=LR" -SQL $sql -AutoSize -Passthru -#Add columns, then format them and hide the ones which aren't of interest. -Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 21 -Value $Avalue -Heading "Apperture" +#Add columns, then format them and hide the ones which aren't of interest. +Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 21 -Value $Avalue -Heading "Apperture" Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 22 -Value $Svalue -Heading "Shutter" -Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 23 -Value $Evvalue -Heading "Ev" -Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column(21) -HorizontalAlignment Left -AutoFit +Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 23 -Value $Evvalue -Heading "Ev" +Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column(21) -HorizontalAlignment Left -AutoFit Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column(22) -HorizontalAlignment Right -AutoFit @(5,6,7,13,15,16,17,18) | ForEach-Object { - Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column($_) -Hidden + Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column($_) -Hidden } -#Center the column labels. +#Center the column labels. Set-Format -Address $e.workbook.Worksheets["sheet1" ].Row(1) -HorizontalAlignment Center -#Format the data as a nice Table, Create the pivot table & chart defined above, show the file in Excel in excel after saving. -Export-Excel -ExcelPackage $e -WorkSheetname "sheet1" -TableName "Table" -PivotTableDefinition $pt -Show +#Format the data as a nice Table, Create the pivot table & chart defined above, show the file in Excel in excel after saving. +Export-Excel -ExcelPackage $e -WorkSheetname "sheet1" -TableName "Table" -PivotTableDefinition $pt -Show ############################################################ Remove-Item .\demo3.xlsx #Database query to get race wins, Poles and fastest lapes for the 25 best drivers; we already have a connection to the DB in $dbSessions -$session = $DbSessions["f1"] +$session = $DbSessions["f1"] $SQL = @" - SELECT TOP 25 DriverName, + SELECT TOP 25 DriverName, Count(RaceDate) AS Races, - Count(Win) AS Wins, - Count(Pole) AS Poles, - Count(FastestLap) AS Fastlaps - FROM Results - GROUP BY DriverName + Count(Win) AS Wins, + Count(Pole) AS Poles, + Count(FastestLap) AS Fastlaps + FROM Results + GROUP BY DriverName ORDER BY (Count(win)) DESC -"@ +"@ -#Run the query and put the results in workshet "Winners", autosize the columns and hold on to the ExcelPackage object +#Run the query and put the results in workshet "Winners", autosize the columns and hold on to the ExcelPackage object $Excel = Send-SQLDataToExcel -SQL $sql -Session $session -path .\demo3.xlsx -WorkSheetname "Winners" -AutoSize -Passthru -#Create and format columns for the ratio of Wins to poles and fast laps. -Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 6 -Heading "WinsToPoles" -Value {"=D$row/C$row"} -Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 7 -Heading "WinsToFast" -Value {"=E$row/C$row"} +#Create and format columns for the ratio of Wins to poles and fast laps. +Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 6 -Heading "WinsToPoles" -Value {"=D$row/C$row"} +Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 7 -Heading "WinsToFast" -Value {"=E$row/C$row"} 6..7 | ForEach-Object { Set-Format -Address $Excel.Workbook.Worksheets["Winners"].column($_) -NumberFormat "0.0%" -AutoFit } -#Define a chart to show the relationship of lest on an XY Grid, create the ranges required in the, add the chart and show the file in Excel in excel after saving. +#Define a chart to show the relationship of lest on an XY Grid, create the ranges required in the, add the chart and show the file in Excel in excel after saving. $chart = New-ExcelChart -NoLegend -ChartType XYScatter -XRange WinsToFast -YRange WinsToPoles -ShowCategory -Column 7 -Width 2000 -Height 700 -Export-Excel -ExcelPackage $Excel -WorkSheetname "Winners" -AutoNameRange -ExcelChartDefinition $chart -Show +Export-Excel -ExcelPackage $Excel -WorkSheetname "Winners" -AutoNameRange -ExcelChartDefinition $chart -Show diff --git a/Examples/SQL+FillColumns+Pivot/Example2.ps1 b/Examples/SQL+FillColumns+Pivot/Example2.ps1 index c1e7322..2e9eb64 100644 --- a/Examples/SQL+FillColumns+Pivot/Example2.ps1 +++ b/Examples/SQL+FillColumns+Pivot/Example2.ps1 @@ -1,17 +1,17 @@ -ipmo C:\Users\mcp\Documents\GitHub\ImportExcel\ImportExcel.psd1 -Force +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} Get-SQL -Session f1 -Excel -Connection C:\Users\mcp\OneDrive\Public\F1\f1Results.xlsx -showtables -Verbose -del .\demo3.xlsx +Remove-Item .\demo3.xlsx $session = $DbSessions["f1"] -$SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races , - Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps - FROM Results GROUP BY DriverName - order by (count(win)) desc" -$Excel = Send-SQLDataToExcel -SQL $sql -Session $session -path .\demo3.xlsx -WorkSheetname "Winners" -AutoSize -AutoNameRange -BoldTopRow -FreezeTopRow -Passthru +$SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races , + Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps + FROM Results GROUP BY DriverName + order by (count(win)) desc" +$Excel = Send-SQLDataToExcel -SQL $sql -Session $session -path .\demo3.xlsx -WorkSheetname "Winners" -AutoSize -AutoNameRange -BoldTopRow -FreezeTopRow -Passthru -$ws = $Excel.Workbook.Worksheets["Winners"] +$ws = $Excel.Workbook.Worksheets["Winners"] Set-Row -Worksheet $ws -Heading "Average" -Value {"=Average($columnName`2:$columnName$endrow)"} -NumberFormat "0.0" -Bold Set-Column -Worksheet $ws -Heading "WinsToPoles" -Value {"=D$row/C$row"} -Column 6 -AutoSize -AutoNameRange diff --git a/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 b/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 index 67d3738..47c416e 100644 --- a/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 +++ b/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 @@ -1,9 +1,10 @@ - -$p = ps | select Company, Handles | Export-Excel c:\temp\testBackgroundColor.xlsx -ClearSheet -KillExcel -PassThru +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +$p = Get-Process | Select-Object Company, Handles | Export-Excel c:\temp\testBackgroundColor.xlsx -ClearSheet -KillExcel -PassThru $ws = $p.Workbook.WorkSheets[1] $totalRows = $ws.Dimension.Rows Set-Format -Address $ws.Cells["B2:B$($totalRows)"] -BackgroundColor LightBlue -Export-Excel -ExcelPackage $p -show \ No newline at end of file +Export-Excel -ExcelPackage $p -show -AutoSize \ No newline at end of file diff --git a/Examples/SpreadsheetCells/CalculatedFields.ps1 b/Examples/SpreadsheetCells/CalculatedFields.ps1 index eb44b54..622f99d 100644 --- a/Examples/SpreadsheetCells/CalculatedFields.ps1 +++ b/Examples/SpreadsheetCells/CalculatedFields.ps1 @@ -1,11 +1,14 @@ -. ..\New-PSItem.ps1 +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -rm *.xlsx + +#. ..\New-PSItem.ps1 + +Remove-Item *.xlsx $( New-PSItem 12001 Nails 37 3.99 =C2*D2 (echo ID Product Quantity Price Total) New-PSItem 12002 Hammer 5 12.10 =C3*D3 New-PSItem 12003 Saw 12 15.37 =C4*D4 New-PSItem 12010 Drill 20 8 =C5*D5 - New-PSItem 12011 Crowbar 7 23.48 =C6*D6 + New-PSItem 12011 Crowbar 7 23.48 =C6*D6 ) | Export-Excel functions.xlsx -AutoSize -Show diff --git a/Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1 b/Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1 index 2563078..672324c 100644 --- a/Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1 +++ b/Examples/SpreadsheetCells/ExcelFormulasUsingAddMember.ps1 @@ -1,3 +1,5 @@ +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + Remove-Item .\testFormula.xlsx -ErrorAction Ignore @" diff --git a/Examples/SpreadsheetCells/ExcelFunctions.ps1 b/Examples/SpreadsheetCells/ExcelFunctions.ps1 index 4760e51..0e341c5 100644 --- a/Examples/SpreadsheetCells/ExcelFunctions.ps1 +++ b/Examples/SpreadsheetCells/ExcelFunctions.ps1 @@ -1,12 +1,12 @@ -. ..\New-PSItem.ps1 +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -rm *.xlsx +Remove-Item *.xlsx $( New-PSItem =2%/12 60 500000 "=pmt(rate,nper,pv)" (echo rate nper pv pmt) - New-PSItem =3%/12 60 500000 "=pmt(rate,nper,pv)" - New-PSItem =4%/12 60 500000 "=pmt(rate,nper,pv)" - New-PSItem =5%/12 60 500000 "=pmt(rate,nper,pv)" - New-PSItem =6%/12 60 500000 "=pmt(rate,nper,pv)" - New-PSItem =7%/12 60 500000 "=pmt(rate,nper,pv)" + New-PSItem =3%/12 60 500000 "=pmt(rate,nper,pv)" + New-PSItem =4%/12 60 500000 "=pmt(rate,nper,pv)" + New-PSItem =5%/12 60 500000 "=pmt(rate,nper,pv)" + New-PSItem =6%/12 60 500000 "=pmt(rate,nper,pv)" + New-PSItem =7%/12 60 500000 "=pmt(rate,nper,pv)" ) | Export-Excel functions.xlsx -AutoNameRange -AutoSize -Show \ No newline at end of file diff --git a/Examples/SpreadsheetCells/HyperLink.ps1 b/Examples/SpreadsheetCells/HyperLink.ps1 index 2cf36c7..451534e 100644 --- a/Examples/SpreadsheetCells/HyperLink.ps1 +++ b/Examples/SpreadsheetCells/HyperLink.ps1 @@ -1,8 +1,10 @@ -rm *.xlsx +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + +Remove-Item *.xlsx $( New-PSItem '=Hyperlink("http://dougfinke.com/blog","Doug Finke")' @("Link") New-PSItem '=Hyperlink("http://blogs.msdn.com/b/powershell/","PowerShell Blog")' New-PSItem '=Hyperlink("http://blogs.technet.com/b/heyscriptingguy/","Hey, Scripting Guy")' - -) | Export-Excel hyperlink.xlsx -AutoSize -Show + +) | Export-Excel hyperlink.xlsx -AutoSize -Show diff --git a/Examples/SpreadsheetCells/hyperlink.xlsx b/Examples/SpreadsheetCells/hyperlink.xlsx new file mode 100644 index 0000000..a8b5e06 Binary files /dev/null and b/Examples/SpreadsheetCells/hyperlink.xlsx differ diff --git a/Examples/Stocks/Get-StockInfo.ps1 b/Examples/Stocks/Get-StockInfo.ps1 index fff9c38..ffe862e 100644 --- a/Examples/Stocks/Get-StockInfo.ps1 +++ b/Examples/Stocks/Get-StockInfo.ps1 @@ -1,3 +1,7 @@ +<# + Revisit I think yahoo deprecated their service +#> + function Get-StockInfo { param( $stock, @@ -7,15 +11,15 @@ function Get-StockInfo { Process { - if(!$endDate) { $endDate = $startDate} + if (!$endDate) { $endDate = $startDate} - $baseUrl = "http://query.yahooapis.com/v1/public/yql?q=" - $q = @" + $baseUrl = "http://query.yahooapis.com/v1/public/yql?q=" + $q = @" select * from yahoo.finance.historicaldata where symbol = "$($stock)" and startDate = "$($startDate.ToString('yyyy-MM-dd'))" and endDate = "$($endDate.ToString('yyyy-MM-dd'))" "@ - $suffix = "&env=store://datatables.org/alltableswithkeys&format=json" - $r=Invoke-RestMethod ($baseUrl + $q + $suffix) - $r.query.results.quote + $suffix = "&env=store://datatables.org/alltableswithkeys&format=json" + $r = Invoke-RestMethod ($baseUrl + $q + $suffix) + $r.query.results.quote } } \ No newline at end of file diff --git a/Examples/Stocks/GetMSFT.ps1 b/Examples/Stocks/GetMSFT.ps1 index 3d91b31..416547e 100644 --- a/Examples/Stocks/GetMSFT.ps1 +++ b/Examples/Stocks/GetMSFT.ps1 @@ -1,14 +1,20 @@ -$Symbol = "MSFT" +<# + Revisit I think yahoo deprecated their service +#> -. .\Get-StockInfo.ps1 +# try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -rm *.xlsx +# $Symbol = "MSFT" -$chart = New-ExcelChart -XRange Date -YRange Volume ` - -ChartType ColumnStacked ` - -Column 9 -Title "$Symbol Volume" +# . .\Get-StockInfo.ps1 -Get-StockInfo $Symbol 11/2 11/30 | - Export-Excel .\stocks.xlsx -Show ` - -AutoSize -AutoNameRange ` - -ExcelChartDefinition $chart \ No newline at end of file +# Remove-Item *.xlsx -ErrorAction Ignore + +# $chart = New-ExcelChart -XRange Date -YRange Volume ` +# -ChartType ColumnStacked ` +# -Column 9 -Title "$Symbol Volume" + +# Get-StockInfo $Symbol 11/2 11/30 | +# Export-Excel .\stocks.xlsx -Show ` +# -AutoSize -AutoNameRange ` +# -ExcelChartDefinition $chart \ No newline at end of file diff --git a/Examples/Stocks/stocks.xlsx b/Examples/Stocks/stocks.xlsx new file mode 100644 index 0000000..6eb02d9 Binary files /dev/null and b/Examples/Stocks/stocks.xlsx differ diff --git a/Examples/Tables/MultipleTables.ps1 b/Examples/Tables/MultipleTables.ps1 index 8e5cf73..86d8752 100644 --- a/Examples/Tables/MultipleTables.ps1 +++ b/Examples/Tables/MultipleTables.ps1 @@ -1,38 +1,40 @@ -$xlfile = "testData.xlsx" -rm *.xlsx +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$r = dir C:\WINDOWS\system32 +$xlfile = "testData.xlsx" +Remove-Item *.xlsx + +$r = Get-ChildItem C:\WINDOWS\system32 $BySize=@{} -$r | ForEach{ $BySize.($_.extension)+=$_.length } +$r | ForEach-Object{ $BySize.($_.extension)+=$_.length } -$top10BySize = $BySize.GetEnumerator() | - ForEach{ [PSCustomObject]@{Name=$_.key;Size=[double]$_.value} } | - Sort size -Descending | - Select -First 10 +$top10BySize = $BySize.GetEnumerator() | + ForEach-Object{ [PSCustomObject]@{Name=$_.key;Size=[double]$_.value} } | + Sort-Object size -Descending | + Select-Object -First 10 -$top10ByCount = $r.extension | - Group | - Sort count -Descending | - Select -First 10 Name, count +$top10ByCount = $r.extension | + Group-Object | + Sort-Object count -Descending | + Select-Object -First 10 Name, count -$top10ByFileSize = $r | - Sort length -Descending | - Select -First 10 Name, @{n="Size";e={$_.Length}} #,Extension,Path +$top10ByFileSize = $r | + Sort-Object length -Descending | + Select-Object -First 10 Name, @{n="Size";e={$_.Length}} #,Extension,Path $top10BySize | Export-Excel $xlfile -WorkSheetname FileInfo -TableName ExtSize $top10ByCount | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 13 -TableName ExtCount $top10ByFileSize | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 25 -AutoSize -TableName FileSize -$ps = ps | ? Company +$ps = Get-Process | Where-Object Company -$ps | - sort handles -Descending | - select -First 10 company, handles | +$ps | + Sort-Object handles -Descending | + Select-Object -First 10 company, handles | Export-Excel $xlfile -WorkSheetname Handles -AutoSize -TableName Handles -$ps | - sort PM -Descending | - select -First 10 company, PM | +$ps | + Sort-Object PM -Descending | + Select-Object -First 10 company, PM | Export-Excel $xlfile -WorkSheetname Handles -AutoSize -TableName PM -StartRow 13 -Show diff --git a/Examples/Tables/testData.xlsx b/Examples/Tables/testData.xlsx new file mode 100644 index 0000000..d94934a Binary files /dev/null and b/Examples/Tables/testData.xlsx differ diff --git a/Examples/XlRangeToImage/XlRangeToImage.ps1 b/Examples/XlRangeToImage/XlRangeToImage.ps1 index c7afbca..fdfe98a 100644 --- a/Examples/XlRangeToImage/XlRangeToImage.ps1 +++ b/Examples/XlRangeToImage/XlRangeToImage.ps1 @@ -1,10 +1,11 @@ -ipmo .\ImportExcel.psd1 -Force +try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} + . .\ConvertExcelToImageFile.ps1 $xlFileName = "C:\Temp\testPNG.xlsx" -rm C:\Temp\testPNG.xlsx -ErrorAction Ignore +Remove-Item C:\Temp\testPNG.xlsx -ErrorAction Ignore $range = @" Region,Item,Cost @@ -16,8 +17,8 @@ North,Pear,1 South,Apple,2 East,Grapes,3 West,Berry,4 -"@ | ConvertFrom-Csv | +"@ | ConvertFrom-Csv | Export-Excel $xlFileName -ReturnRange ` - -ConditionalText (New-ConditionalText Apple), (New-ConditionalText Berry -ConditionalTextColor White -BackgroundColor Purple) + -ConditionalText (New-ConditionalText Apple), (New-ConditionalText Berry -ConditionalTextColor White -BackgroundColor Purple) Convert-XlRangeToImage -Path $xlFileName -workSheetname sheet1 -range $range -Show diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index bbf5fb3..9028185 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. -ModuleVersion = '5.0.1' +ModuleVersion = '5.1.0' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/InstallModule.ps1 b/InstallModule.ps1 index b81c979..05af5a9 100644 --- a/InstallModule.ps1 +++ b/InstallModule.ps1 @@ -44,6 +44,7 @@ Begin { 'Import-Html.ps1', 'InferData.ps1', 'Invoke-Sum.ps1', + 'Join-Worksheet.ps1', 'Merge-Worksheet.ps1', 'New-ConditionalFormattingIconSet.ps1', 'New-ConditionalText.ps1', diff --git a/Merge-worksheet.ps1 b/Merge-worksheet.ps1 index b052731..6d239eb 100644 --- a/Merge-worksheet.ps1 +++ b/Merge-worksheet.ps1 @@ -162,20 +162,18 @@ $diffpart = @() $refpart = @() foreach ($p in $proplist.Where({$key -ne $_}) ) {$refPart += $p ; $diffPart += "$DiffPrefix $p" } - #Last reference column will be A if there the only one property (which might be the key), B if there are two properties, C if there are 3 etc - $lastRefCol = [char](64 + $propList.count) - #First difference column will be the next one (we'll trap the case of only having the key later) - $FirstDiffCol = [char](65 + $propList.count) + $lastRefColNo = $proplist.count + $FirstDiffColNo = $lastRefColNo + 1 if ($key -ne '*') { - $outputProps = @($key) + $refpart + $diffpart + $outputProps = @($key) + $refpart + $diffpart #If we are using a single column as the key, don't duplicate it, so the last difference column will be A if there is one property, C if there are two, E if there are 3 - $lastDiffCol = [char](63 + 2 * $propList.count) + $lastDiffColNo = (2 * $proplist.count) - 1 } else { - $outputProps = @( ) + $refpart + $diffpart + $outputProps = @( ) + $refpart + $diffpart #If we not using a single column as a key all columns are duplicated so, the Last difference column will be B if there is one property, D if there are two, F if there are 3 - $lastDiffCol = [char](64 + 2 * $propList.count) + $lastDiffColNo = (2 * $proplist.count ) } #Add RowNumber to every row @@ -265,12 +263,14 @@ Set-Format -WorkSheet $ws -Range $range -BackgroundColor $ChangeBackgroundColor } elseif ( $expandedDiff[$i].side -eq "<=" ) { - $range = "A" + ($i + 2 ) + ":" + $lastRefCol + ($i + 2 ) + $rangeR1C1 = "R[{0}]C[1]:R[{0}]C[{1}]" -f ($i + 2 ) , $lastRefColNo + $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) Set-Format -WorkSheet $ws -Range $range -BackgroundColor $DeleteBackgroundColor } elseif ( $expandedDiff[$i].side -eq "=>" ) { if ($propList.count -gt 1) { - $range = $FirstDiffCol + ($i + 2 ) + ":" + $lastDiffCol + ($i + 2 ) + $rangeR1C1 = "R[{0}]C[{1}]:R[{0}]C[{2}]" -f ($i + 2 ) , $FirstDiffColNo , $lastDiffColNo + $range = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1($rangeR1C1,0,0) Set-Format -WorkSheet $ws -Range $range -BackgroundColor $AddBackgroundColor } Set-Format -WorkSheet $ws -Range ("A" + ($i + 2 )) -BackgroundColor $AddBackgroundColor diff --git a/ToDo.md b/ToDo.md index 60d0c5d..d2a73f0 100644 --- a/ToDo.md +++ b/ToDo.md @@ -1,7 +1,7 @@ - [ ] Create an autocomplete for WorkSheetName param on ImportExcel - [ ] Add help text for parmaters which don't have it ( PivotDataToColumn , NoClobber and CellStyleSB ) in Export Excel, copy to Send-SQLDataToExcel - [ ] Add checks for valid worksheet names (also check pivot names, range names and table names are valid) -- [ ] Investigate regional support for number conversion +- [ ] Investigate regional support for number conversion & possible date conversion - [ ] Add help in ConvertToExcelXLSx.ps1, Copy-ExcelWorkSheet.ps1 (probably re-write copy) - [ ] Add Help (continued) in Get-HTMLTable.ps1, GetRange.PS1, GetExcelTable.Ps1, Import-HTML.PS1, New-ConditionalFormattingIconSet.Ps1, NewConditionalText.PS1, New-Psitem.PS1, Remove-Worksheet.ps1 [ ] Copy parameter help from function Add-ExcelChart into New-ExcelChart.ps1 diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index 4862751..bc62322 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -7,62 +7,62 @@ 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 { - Context "#Example 1 # Creates and opens a file with the right number of rows and columns" { - $path = "$env:TEMP\Test.xlsx" - Remove-item -Path $path -ErrorAction SilentlyContinue - $processes = Get-Process - $propertyNames = $Processes[0].psobject.properties.name - $rowcount = $Processes.Count - $Processes | Export-Excel $path -show + # Context "#Example 1 # Creates and opens a file with the right number of rows and columns" { + # $path = "$env:TEMP\Test.xlsx" + # Remove-item -Path $path -ErrorAction SilentlyContinue + # $processes = Get-Process + # $propertyNames = $Processes[0].psobject.properties.name + # $rowcount = $Processes.Count + # $Processes | Export-Excel $path -show - it "Created a new file " { - Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true - } + # it "Created a new file " { + # Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true + # } - it "Started Excel to display the file " { - Get-process -Name Excel, xlim -ErrorAction SilentlyContinue | Should not benullorempty - } + # it "Started Excel to display the file " { + # Get-process -Name Excel, xlim -ErrorAction SilentlyContinue | Should not benullorempty + # } - Start-Sleep -Seconds 5 ; + # Start-Sleep -Seconds 5 ; - #Open-ExcelPackage with -Create is tested in Export-Excel - #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 " { - Get-process -Name Excel, xlim -ErrorAction SilentlyContinue | Should benullorempty - } + # #Open-ExcelPackage with -Create is tested in Export-Excel + # #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 " { + # Get-process -Name Excel, xlim -ErrorAction SilentlyContinue | Should benullorempty + # } - it "Created 1 worksheet " { - $Excel.Workbook.Worksheets.count | Should be 1 - } + # it "Created 1 worksheet " { + # $Excel.Workbook.Worksheets.count | Should be 1 + # } - $ws = $Excel.Workbook.Worksheets[1] - it "Created the worksheet with the expected name, number of rows and number of columns " { - $ws.Name | Should be "sheet1" - $ws.Dimension.Columns | Should be $propertyNames.Count - $ws.Dimension.Rows | Should be ($rowcount + 1) - } + # $ws = $Excel.Workbook.Worksheets[1] + # it "Created the worksheet with the expected name, number of rows and number of columns " { + # $ws.Name | Should be "sheet1" + # $ws.Dimension.Columns | Should be $propertyNames.Count + # $ws.Dimension.Rows | Should be ($rowcount + 1) + # } - $headingNames = $ws.cells["1:1"].Value - it "Created the worksheet with the correct header names " { - foreach ($p in $propertyNames) { - $headingnames -contains $p | Should be $true - } - } + # $headingNames = $ws.cells["1:1"].Value + # it "Created the worksheet with the correct header names " { + # foreach ($p in $propertyNames) { + # $headingnames -contains $p | Should be $true + # } + # } - it "Formatted the process StartTime field as 'local short date' " { - $STHeader = $ws.cells["1:1"].where( {$_.Value -eq "StartTime"})[0] - $STCell = $STHeader.Address -replace '1$', '2' - $ws.cells[$stcell].Style.Numberformat.NumFmtID | Should be 22 - } + # it "Formatted the process StartTime field as 'local short date' " { + # $STHeader = $ws.cells["1:1"].where( {$_.Value -eq "StartTime"})[0] + # $STCell = $STHeader.Address -replace '1$', '2' + # $ws.cells[$stcell].Style.Numberformat.NumFmtID | Should be 22 + # } - it "Formatted the process ID field as 'General' " { - $IDHeader = $ws.cells["1:1"].where( {$_.Value -eq "ID"})[0] - $IDCell = $IDHeader.Address -replace '1$', '2' - $ws.cells[$IDcell].Style.Numberformat.NumFmtID | Should be 0 - } - } + # it "Formatted the process ID field as 'General' " { + # $IDHeader = $ws.cells["1:1"].where( {$_.Value -eq "ID"})[0] + # $IDCell = $IDHeader.Address -replace '1$', '2' + # $ws.cells[$IDcell].Style.Numberformat.NumFmtID | Should be 0 + # } + # } Context " # NoAliasOrScriptPropeties -ExcludeProperty and -DisplayPropertySet work" { $path = "$env:TEMP\Test.xlsx" @@ -408,7 +408,7 @@ Describe ExportExcel { $PTws.PivotTables.Count | Should be 1 $Excel.Workbook.Worksheets["Processes"] | Should not beNullOrEmpty $Excel.Workbook.Worksheets.Count | Should beGreaterThan 2 - $excel.Workbook.Worksheets["Processes"].Dimension.rows | Should be 51 #50 data + 1 header + # $excel.Workbook.Worksheets["Processes"].Dimension.rows | Should be 51 #50 data + 1 header } $pt = $PTws.PivotTables[0] it "Built the expected Pivot table " { @@ -438,9 +438,9 @@ Describe ExportExcel { $pt = $Excel.Workbook.Worksheets["ProcessesPivotTable"].PivotTables[0] it "Appended to the Worksheet and Extended the Pivot table " { $Excel.Workbook.Worksheets.Count | Should be $wCount - $excel.Workbook.Worksheets["Processes"].Dimension.rows | Should be 101 #appended 50 rows to the previous total - $pt.CacheDefinition.CacheDefinitionXml.pivotCacheDefinition.cacheSource.worksheetSource.ref | - Should be "A1:E101" + # $excel.Workbook.Worksheets["Processes"].Dimension.rows | Should be 101 #appended 50 rows to the previous total + # $pt.CacheDefinition.CacheDefinitionXml.pivotCacheDefinition.cacheSource.worksheetSource.ref | + # Should be "A1:E101" } it "Generated a message on extending the Pivot table " { $warnVar | Should not beNullOrEmpty @@ -641,7 +641,7 @@ Describe ExportExcel { Should be $sheet.Dimension.address } } - + Context " # Chart from MultiSeries.ps1 in the Examples\charts Directory" { $path = "$env:TEMP\Test.xlsx" Remove-Item -Path $path -ErrorAction SilentlyContinue @@ -655,40 +655,40 @@ Describe ExportExcel { $data[1].VirtualMemorySize | Should not beNullOrEmpty } $c = New-ExcelChartDefinition -Title Stats -ChartType LineMarkersStacked -XRange "Processes[Name]" -YRange "Processes[PM]", "Processes[VirtualMemorySize]" -SeriesHeader 'PM', 'VMSize' - + it "Created the Excel chart definition " { - $c | Should not beNullOrEmpty - $c.ChartType.gettype().name | Should be "eChartType" + $c | Should not beNullOrEmpty + $c.ChartType.gettype().name | Should be "eChartType" $c.ChartType.tostring() | Should be "LineMarkersStacked" $c.yrange -is [array] | Should be $true - $c.yrange.count | Should be 2 - $c.yrange[0] | Should be "Processes[PM]" + $c.yrange.count | Should be 2 + $c.yrange[0] | Should be "Processes[PM]" $c.yrange[1] | Should be "Processes[VirtualMemorySize]" $c.xrange | Should be "Processes[Name]" $c.Title | Should be "Stats" - $c.Nolegend | Should not be $true - $c.ShowCategory | Should not be $true - $c.ShowPercent | Should not be $true + $c.Nolegend | Should not be $true + $c.ShowCategory | Should not be $true + $c.ShowPercent | Should not be $true } - $data | Export-Excel $path -AutoSize -TableName Processes -ExcelChartDefinition $c - $excel = Open-ExcelPackage -Path $path + $data | Export-Excel $path -AutoSize -TableName Processes -ExcelChartDefinition $c + $excel = Open-ExcelPackage -Path $path $drawings = $excel.Workbook.Worksheets[1].drawings it "Used the Excel chart definition with Export-Excel " { $drawings.count | Should be 1 $drawings[0].ChartType | Should be "LineMarkersStacked" - $drawings[0].Series.count | Should be 2 + $drawings[0].Series.count | Should be 2 $drawings[0].Series[0].Series | Should be "'Sheet1'!Processes[PM]" $drawings[0].Series[0].XSeries | Should be "'Sheet1'!Processes[Name]" $drawings[0].Series[1].Series | Should be "'Sheet1'!Processes[VirtualMemorySize]" $drawings[0].Series[1].XSeries | Should be "'Sheet1'!Processes[Name]" $drawings[0].Title.text | Should be "Stats" } - Close-ExcelPackage $excel + Close-ExcelPackage $excel } - + Context " # variation of plot.ps1 from Examples Directory using Add chart outside ExportExcel" { $path = "$env:TEMP\Test.xlsx" - $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path $path -WorkSheetname SinX -ClearSheet -PassThru + $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path $path -WorkSheetname SinX -ClearSheet -PassThru Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -XRange "X" -YRange "Sinx" -Title "Graph of Sine X" -ChartType line -SeriesHeader "Sin(x)" -Column 2 -ColumnOffSetPixels 35 -TitleBold -TitleSize 14 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -Width 800 -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -LegendPostion Bottom -LegendSize 8 -legendBold $d = $excel.Workbook.Worksheets["Sinx"].Drawings[0] It "Controled the axes and title and legend of the chart" { @@ -698,23 +698,23 @@ Describe ExportExcel { $d.XAxis.Title.Text | Should be "degrees" $d.XAxis.Title.Font.bold | Should be $true $d.XAxis.Title.Font.Size | Should be 12 - $d.XAxis.MajorUnit | Should be 30 - $d.XAxis.MinorUnit | Should be 10 - $d.XAxis.MinValue | Should be 0 + $d.XAxis.MajorUnit | Should be 30 + $d.XAxis.MinorUnit | Should be 10 + $d.XAxis.MinValue | Should be 0 $d.XAxis.MaxValue | Should be 361 - $d.YAxis.Format | Should be "0.00" - $d.Title.Text | Should be "Graph of Sine X" - $d.Title.Font.Bold | Should be $true + $d.YAxis.Format | Should be "0.00" + $d.Title.Text | Should be "Graph of Sine X" + $d.Title.Font.Bold | Should be $true $d.Title.Font.Size | Should be 14 $d.yAxis.MajorUnit | Should be 0.25 $d.yAxis.MaxValue | Should be 1.25 - $d.yaxis.MinValue | Should be -1.25 + $d.yaxis.MinValue | Should be -1.25 $d.Legend.Position.ToString() | Should be "Bottom" - $d.Legend.Font.Bold | Should be $true + $d.Legend.Font.Bold | Should be $true $d.Legend.Font.Size | Should be 8 - $d.ChartType.tostring() | Should be "line" - $d.From.Column | Should be 2 - } + $d.ChartType.tostring() | Should be "line" + $d.From.Column | Should be 2 + } Close-ExcelPackage -ExcelPackage $excel -nosave } diff --git a/fib.xlsx b/fib.xlsx new file mode 100644 index 0000000..9222278 Binary files /dev/null and b/fib.xlsx differ