mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
See readme.md
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -690,7 +690,7 @@
|
||||
}
|
||||
#If named range exists, update it, else create it
|
||||
if ($ws.Names[$RangeName]) { $ws.Names[$rangename].Address = $ws.Cells[$dataRange].FullAddressAbsolute }
|
||||
else {$ws.Names.Add($RangeName, $ws.Cells[$dataRange]) | Out-Null }
|
||||
else {$ws.Names.Add($RangeName, $ws.Cells[$0ange]) | Out-Null }
|
||||
}
|
||||
}
|
||||
Catch { Write-Warning -Message "Failed adding range '$RangeName' to worksheet '$WorkSheetname': $_" }
|
||||
@@ -822,8 +822,8 @@
|
||||
|
||||
foreach ($chartDef in $ExcelChartDefinition) {
|
||||
$params = @{}
|
||||
$chardef.PSObject.Properties | ForEach-Object {if ($_.value -ne $null) {$params[$_.name] = $_.value}}
|
||||
Add-ExcelChart $params
|
||||
$chartDef.PSObject.Properties | ForEach-Object {if ($_.value -ne $null) {$params[$_.name] = $_.value}}
|
||||
Add-ExcelChart @params
|
||||
}
|
||||
|
||||
foreach ($ct in $ConditionalText) {
|
||||
@@ -841,8 +841,8 @@
|
||||
|
||||
if ($CellStyleSB) {
|
||||
try {
|
||||
$TotalRows = $ws.Dimension.Rows
|
||||
$LastColumn = (Get-ExcelColumnName $ws.Dimension.Columns).ColumnName
|
||||
$TotalRows = $ws.Dimension.Rows
|
||||
$LastColumn = $ws.Dimension.Address -replace "^.*:(\w*)\d+$" , '$1'
|
||||
& $CellStyleSB $ws $TotalRows $LastColumn
|
||||
}
|
||||
catch {Write-Warning -Message "Failed processing CellStyleSB in worksheet '$WorkSheetname': $_"}
|
||||
@@ -1164,34 +1164,88 @@ function Add-PivotTable {
|
||||
}
|
||||
}
|
||||
function Add-ExcelChart {
|
||||
[cmdletbinding()]
|
||||
param(
|
||||
$Worksheet,
|
||||
$Title = "Chart Title",
|
||||
$Header,
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet,
|
||||
[String]$Title = "Chart Title",
|
||||
#$Header, Not used but referenced previously
|
||||
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked",
|
||||
$XRange,
|
||||
$YRange,
|
||||
$Width = 500,
|
||||
$Height = 350,
|
||||
$Row = 0,
|
||||
$RowOffSetPixels = 10,
|
||||
$Column = 6,
|
||||
$ColumnOffSetPixels = 5,
|
||||
[int]$Width = 500,
|
||||
[int]$Height = 350,
|
||||
[int]$Row = 0,
|
||||
[int]$RowOffSetPixels = 10,
|
||||
[int]$Column = 6,
|
||||
[int]$ColumnOffSetPixels = 5,
|
||||
[OfficeOpenXml.Drawing.Chart.eLegendPosition]$LegendPostion,
|
||||
$LegendSize,
|
||||
[Switch]$legendBold,
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$ShowPercent,
|
||||
$SeriesHeader
|
||||
)
|
||||
$SeriesHeader,
|
||||
[Switch]$TitleBold,
|
||||
[Int]$TitleSize ,
|
||||
[String]$XAxisTitleText,
|
||||
[Switch]$XAxisTitleBold,
|
||||
$XAxisTitleSize ,
|
||||
[string]$XAxisNumberformat,
|
||||
[double]$XMajorUnit,
|
||||
[double]$XMinorUnit,
|
||||
[double]$XMaxValue,
|
||||
[double]$XMinValue,
|
||||
[OfficeOpenXml.Drawing.Chart.eAxisPosition]$XAxisPosition ,
|
||||
[String]$YAxisTitleText,
|
||||
[Switch]$YAxisTitleBold,
|
||||
$YAxisTitleSize,
|
||||
[string]$YAxisNumberformat,
|
||||
[double]$YMajorUnit,
|
||||
[double]$YMinorUnit,
|
||||
[double]$YMaxValue,
|
||||
[double]$YMinValue,
|
||||
[OfficeOpenXml.Drawing.Chart.eAxisPosition]$YAxisPosition )
|
||||
try {
|
||||
$ChartName = 'Chart' + (Split-Path -Leaf ([System.IO.path]::GetTempFileName())) -replace 'tmp|\.', ''
|
||||
$chart = $Worksheet.Drawings.AddChart($ChartName, $ChartType)
|
||||
$chart.Title.Text = $Title
|
||||
|
||||
if ($TitleBold) {$chart.Title.Font.Bold = $true}
|
||||
if ($TitleSize) {$chart.Title.Font.Size = $TitleSize}
|
||||
|
||||
if ($NoLegend) { $chart.Legend.Remove() }
|
||||
else {
|
||||
if ($LegendPostion) {$Chart.Legend.Position = $LegendPostion}
|
||||
if ($LegendSize) {$chart.Legend.Font.Size = $LegendSize}
|
||||
if ($legendBold) {$chart.Legend.Font.Bold = $legendBold}
|
||||
}
|
||||
|
||||
if ($XAxisTitleText) {
|
||||
$chart.XAxis.Title.Text = $XAxisTitleText
|
||||
if ($XAxisTitleBold) {$chart.XAxis.Title.Font.Bold = $true}
|
||||
if ($XAxisTitleSize) {$chart.XAxis.Title.Font.Size = $XAxisTitleSize}
|
||||
}
|
||||
if ($XAxisPosition) {$chart.XAxis.AxisPosition = $XAxisPosition}
|
||||
if ($XMajorUnit) {$chart.XAxis.MajorUnit = $XMajorUnit}
|
||||
if ($XMinorUnit) {$chart.XAxis.MinorUnit = $XMinorUnit}
|
||||
if ($XMinValue) {$chart.XAxis.MinValue = $XMinValue}
|
||||
if ($XMaxValue) {$chart.XAxis.MaxValue = $XMaxValue}
|
||||
if ($XAxisNumberformat) {$chart.XAxis.Format = $XAxisNumberformat}
|
||||
|
||||
if ($YAxisTitleText) {
|
||||
$chart.YAxis.Title.Text = $YAxisTitleText
|
||||
if ($YAxisTitleBold) {$chart.YAxis.Title.Font.Bold = $true}
|
||||
if ($YAxisTitleSize) {$chart.YAxis.Title.Font.Size = $YAxisTitleSize}
|
||||
}
|
||||
if ($YAxisPosition) {$chart.YAxis.AxisPosition = $YAxisPosition}
|
||||
if ($YMajorUnit) {$chart.YAxis.MajorUnit = $YMajorUnit}
|
||||
if ($YMinorUnit) {$chart.YAxis.MinorUnit = $YMinorUnit}
|
||||
if ($YMinValue) {$chart.YAxis.MinValue = $YMinValue}
|
||||
if ($YMaxValue) {$chart.YAxis.MaxValue = $YMaxValue}
|
||||
if ($YAxisNumberformat) {$chart.YAxis.Format = $YAxisNumberformat}
|
||||
|
||||
if ($chart.Datalabel -ne $null) {
|
||||
$chart.Datalabel.ShowCategory = [boolean]$ShowCategory
|
||||
$chart.Datalabel.ShowPercent = [boolean]$ShowPercent
|
||||
$chart.Datalabel.ShowPercent = [boolean]$ShowPercent
|
||||
}
|
||||
|
||||
$chart.SetPosition($Row, $RowOffsetPixels, $Column, $ColumnOffsetPixels)
|
||||
@@ -1201,13 +1255,13 @@ function Add-ExcelChart {
|
||||
if ($chartDefCount -eq 1) {
|
||||
$Series = $chart.Series.Add($YRange, $XRange)
|
||||
if ($SeriesHeader) { $Series.Header = $SeriesHeader}
|
||||
else { $Series.Header = 'Series 1'}
|
||||
else { $Series.Header = 'Series 1'}
|
||||
}
|
||||
else {
|
||||
for ($idx = 0; $idx -lt $chartDefCount; $idx += 1) {
|
||||
$Series = $chart.Series.Add($YRange[$idx], $XRange)
|
||||
if ($SeriesHeader.Count -gt 0) { $Series.Header = $SeriesHeader[$idx] }
|
||||
else { $Series.Header = "Series $($idx)"}
|
||||
else { $Series.Header = "Series $($idx)"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function Get-XYRange {
|
||||
param($targetData)
|
||||
|
||||
$record = $targetData| select -First 1
|
||||
$record = $targetData| Select-Object -First 1
|
||||
$p=$record.psobject.Properties.name
|
||||
|
||||
$infer = for ($idx = 0; $idx -lt $p.Count; $idx++) {
|
||||
@@ -15,12 +15,12 @@ function Get-XYRange {
|
||||
Name = $name
|
||||
Value = $value
|
||||
DataType = $result.DataType
|
||||
ExcelColumn = (Get-ExcelColumnName ($idx+1)).ColumnName
|
||||
ExcelColumn = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[1]C[$($idx+1)]", 0 , 0) -replace "\d+", "" #(Get-ExcelColumnName ($idx + 1)).ColumnName
|
||||
}
|
||||
}
|
||||
|
||||
[PSCustomObject]@{
|
||||
XRange = $infer | ? {$_.datatype -match 'string'} | select -First 1 excelcolumn, name
|
||||
YRange = $infer | ? {$_.datatype -match 'int|double'} |select -First 1 excelcolumn, name
|
||||
XRange = $infer | ? {$_.datatype -match 'string'} | Select-Object -First 1 excelcolumn, name
|
||||
YRange = $infer | ? {$_.datatype -match 'int|double'} |Select-Object -First 1 excelcolumn, name
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,38 @@
|
||||
function New-ExcelChart {
|
||||
function New-ExcelChartDefinition {
|
||||
[cmdletbinding()]
|
||||
[Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook.
|
||||
param(
|
||||
$Title="Chart Title",
|
||||
$Title = "Chart Title",
|
||||
$Header,
|
||||
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="ColumnStacked",
|
||||
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = "ColumnStacked",
|
||||
$XRange,
|
||||
$YRange,
|
||||
$Width=500,
|
||||
$Height=350,
|
||||
$Row=0,
|
||||
$RowOffSetPixels=10,
|
||||
$Column=6,
|
||||
$ColumnOffSetPixels=5,
|
||||
$Width = 500,
|
||||
$Height = 350,
|
||||
$Row = 0,
|
||||
$RowOffSetPixels = 10,
|
||||
$Column = 6,
|
||||
$ColumnOffSetPixels = 5,
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$ShowPercent,
|
||||
$SeriesHeader
|
||||
)
|
||||
|
||||
if ( $Header ) {Write-Warning "The header parameter is ignored."} #Nothing was done with it when creating a chart.
|
||||
[PSCustomObject]@{
|
||||
Title=$Title
|
||||
Header=$Header
|
||||
ChartType=$ChartType
|
||||
XRange=$XRange
|
||||
YRange=$YRange
|
||||
Width=$Width
|
||||
Height=$Height
|
||||
Row=$Row
|
||||
RowOffSetPixels=$RowOffSetPixels
|
||||
Column=$Column
|
||||
ColumnOffSetPixels=$ColumnOffSetPixels
|
||||
NoLegend = if($NoLegend) {$true} else {$false}
|
||||
ShowCategory = if($ShowCategory) {$true} else {$false}
|
||||
ShowPercent = if($ShowPercent) {$true} else {$false}
|
||||
SeriesHeader=$SeriesHeader
|
||||
}
|
||||
Title = $Title
|
||||
ChartType = $ChartType
|
||||
XRange = $XRange
|
||||
YRange = $YRange
|
||||
Width = $Width
|
||||
Height = $Height
|
||||
Row = $Row
|
||||
RowOffSetPixels = $RowOffSetPixels
|
||||
Column = $Column
|
||||
ColumnOffSetPixels = $ColumnOffSetPixels
|
||||
NoLegend = $NoLegend -as [Boolean]
|
||||
ShowCategory = $ShowCategory-as [Boolean]
|
||||
ShowPercent = $ShowPercent -as [Boolean]
|
||||
SeriesHeader = $SeriesHeader
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,13 @@ To install to your personal modules folder (e.g. ~\Documents\WindowsPowerShell\M
|
||||
iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/ImportExcel/master/Install.ps1')
|
||||
```
|
||||
|
||||
# What's new
|
||||
# What's new to 4th July 18
|
||||
- Moved chart creatation into its own function (Add-Excel chart) within Export-Excel.ps1. Renamed New-Excelchart to New-ExcelChartDefinition to make it clearer that it is not making anything in the workbook (but for compatiblity put an alias of New-ExcelChart in so existing code does not break). Found -Header does nothing, so removed it.
|
||||
- Fixed a bug introduced into Compare-Worksheet by the change descibed in the June changes below, this meant the font color was only being set in one sheet, when a row was changed. Also found that the PowerShell ISE and shell return Compare-Object resuls in different sequences which broke some tests. Applied a sort to ensure things are in a predictable order.
|
||||
- Added chart tests to Export-Excel.tests.ps1.
|
||||
- Removed (2) calls to Get-ExcelColumnName
|
||||
|
||||
# New in June 18
|
||||
- New commands - Diff , Merge and Join
|
||||
- `Compare-Worksheet` (introduced in 5.0) uses the built in `Compare-object` command, to output a command-line DIFF and/or colour the worksheet to show differences. For example, if my sheets are Windows services the *extra* rows or rows where the startup status has changed get highlighted
|
||||
- `Merge-Worksheet` (also introduced in 5.0) joins two lumps, side by highlighting the differences. So now I can have server A's services and Server Bs Services on the same page. I figured out a way to do multiple sheets. So I can have Server A,B,C,D on one page :-) that is `Merge-MultpleSheets`
|
||||
|
||||
@@ -25,7 +25,7 @@ Describe "Compare Worksheet" {
|
||||
|
||||
$s | Export-Excel -Path $env:temp\server2.xlsx
|
||||
#Assume default worksheet name, (sheet1) and column header for key ("name")
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx"
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" | Sort-Object -Property _row, _file
|
||||
|
||||
Context "Simple comparison output" {
|
||||
it "Found the right number of differences " {
|
||||
@@ -38,8 +38,8 @@ Describe "Compare Worksheet" {
|
||||
$comp[0]._Row | should be 4
|
||||
$comp[1]._Row | should be 4
|
||||
$comp[1].Name | should be $comp[0].Name
|
||||
$comp[1].DisplayName | should be $row4Displayname
|
||||
$comp[0].DisplayName | should be "Changed from the orginal"
|
||||
$comp[0].DisplayName | should be $row4Displayname
|
||||
$comp[1].DisplayName | should be "Changed from the orginal"
|
||||
}
|
||||
it "Found the inserted data row " {
|
||||
$comp | should not beNullOrEmpty
|
||||
@@ -125,14 +125,13 @@ Describe "Compare Worksheet" {
|
||||
|
||||
$s | Select-Object -Property ServiceName, DisplayName, StartType, ServiceType | Export-Excel -Path $env:temp\server2.xlsx -WorkSheetname server2
|
||||
#Assume default worksheet name, (sheet1) and column header for key ("name")
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -WorkSheetName Server1,Server2 -Key ServiceName -Property DisplayName,StartType -AllDataBackgroundColor AliceBlue -BackgroundColor White -FontColor Red
|
||||
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -WorkSheetName Server1,Server2 -Key ServiceName -Property DisplayName,StartType -AllDataBackgroundColor AliceBlue -BackgroundColor White -FontColor Red | Sort-Object _row,_file
|
||||
$xl1 = Open-ExcelPackage -Path "$env:temp\Server1.xlsx"
|
||||
$xl2 = Open-ExcelPackage -Path "$env:temp\Server2.xlsx"
|
||||
|
||||
$s1Sheet = $xl1.Workbook.Worksheets["server1"]
|
||||
$s2Sheet = $xl2.Workbook.Worksheets["server2"]
|
||||
Context "More complex comparison output etc different worksheet names " {
|
||||
Context "More complex comparison: output check and different worksheet names " {
|
||||
it "Found the right number of differences " {
|
||||
$comp | should not beNullOrEmpty
|
||||
$comp.Count | should be 4
|
||||
@@ -143,8 +142,8 @@ Describe "Compare Worksheet" {
|
||||
$comp[0]._Row | should be 4
|
||||
$comp[1]._Row | should be 4
|
||||
$comp[1].ServiceName | should be $comp[0].ServiceName
|
||||
$comp[1].DisplayName | should be $row4Displayname
|
||||
$comp[0].DisplayName | should be "Changed from the orginal"
|
||||
$comp[0].DisplayName | should be $row4Displayname
|
||||
$comp[1].DisplayName | should be "Changed from the orginal"
|
||||
}
|
||||
it "Found the inserted data row " {
|
||||
$comp | should not beNullOrEmpty
|
||||
|
||||
BIN
dashboard.xlsx
BIN
dashboard.xlsx
Binary file not shown.
BIN
test1.xlsx
BIN
test1.xlsx
Binary file not shown.
BIN
testTable.xlsx
BIN
testTable.xlsx
Binary file not shown.
Reference in New Issue
Block a user