mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-23 11:43:53 +00:00
fix naming consitency (case mostly)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[Alias("Range")]
|
||||
$Address ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 1)]
|
||||
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
@@ -51,18 +51,18 @@
|
||||
|
||||
#Allow conditional formatting to work like Set-ExcelRange (with single ADDRESS parameter), split it to get worksheet and range of cells.
|
||||
If ($Address -is [OfficeOpenXml.Table.ExcelTable]) {
|
||||
$WorkSheet = $Address.Address.Worksheet
|
||||
$Worksheet = $Address.Address.Worksheet
|
||||
$Address = $Address.Address.Address
|
||||
}
|
||||
elseif ($Address.Address -and $Address.Worksheet -and -not $WorkSheet) { #Address is a rangebase or similar
|
||||
$WorkSheet = $Address.Worksheet[0]
|
||||
elseif ($Address.Address -and $Address.Worksheet -and -not $Worksheet) { #Address is a rangebase or similar
|
||||
$Worksheet = $Address.Worksheet[0]
|
||||
$Address = $Address.Address
|
||||
}
|
||||
elseif ($Address -is [String] -and $WorkSheet -and $WorkSheet.Names[$Address] ) { #Address is the name of a named range.
|
||||
$Address = $WorkSheet.Names[$Address].Address
|
||||
elseif ($Address -is [String] -and $Worksheet -and $Worksheet.Names[$Address] ) { #Address is the name of a named range.
|
||||
$Address = $Worksheet.Names[$Address].Address
|
||||
}
|
||||
if (($Address -is [OfficeOpenXml.ExcelRow] -and -not $WorkSheet) -or
|
||||
($Address -is [OfficeOpenXml.ExcelColumn] -and -not $WorkSheet) ){ #EPPLUs Can't get the worksheet object from a row or column object, so bail if that was tried
|
||||
if (($Address -is [OfficeOpenXml.ExcelRow] -and -not $Worksheet) -or
|
||||
($Address -is [OfficeOpenXml.ExcelColumn] -and -not $Worksheet) ){ #EPPLUs Can't get the worksheet object from a row or column object, so bail if that was tried
|
||||
Write-Warning -Message "Add-ConditionalFormatting does not support Row or Column objects as an address; use a worksheet and/or specify 'R:R' or 'C:C' instead. "; return
|
||||
}
|
||||
elseif ($Address -is [OfficeOpenXml.ExcelRow]) { #But if we have a column or row object and a worksheet (I don't know *why*) turn them into a string for the range
|
||||
@@ -74,16 +74,16 @@
|
||||
}
|
||||
if ( $Address -is [string] -and $Address -match "!") {$Address = $Address -replace '^.*!',''}
|
||||
#By this point we should have a worksheet object whose ConditionalFormatting collection we will add to. If not, bail.
|
||||
if (-not $worksheet -or $WorkSheet -isnot [OfficeOpenXml.ExcelWorksheet]) {write-warning "You need to provide a worksheet object." ; return}
|
||||
if (-not $worksheet -or $Worksheet -isnot [OfficeOpenXml.ExcelWorksheet]) {write-warning "You need to provide a worksheet object." ; return}
|
||||
#region create a rule of the right type
|
||||
if ($RuleType -match 'IconSet$') {Write-warning -Message "You cannot configure a Icon-Set rule in this way; please use -$RuleType <SetName>." ; return}
|
||||
if ($PSBoundParameters.ContainsKey("DataBarColor" ) ) {if ($DataBarColor -is [string]) {$DataBarColor = [System.Drawing.Color]::$DataBarColor }
|
||||
$rule = $WorkSheet.ConditionalFormatting.AddDatabar( $Address , $DataBarColor )
|
||||
$rule = $Worksheet.ConditionalFormatting.AddDatabar( $Address , $DataBarColor )
|
||||
}
|
||||
elseif ($PSBoundParameters.ContainsKey("ThreeIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddThreeIconSet($Address , $ThreeIconsSet)}
|
||||
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFourIconSet( $Address , $FourIconsSet )}
|
||||
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFiveIconSet( $Address , $FiveIconsSet )}
|
||||
else {$rule = ($WorkSheet.ConditionalFormatting)."Add$RuleType"($Address ) }
|
||||
elseif ($PSBoundParameters.ContainsKey("ThreeIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddThreeIconSet($Address , $ThreeIconsSet)}
|
||||
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddFourIconSet( $Address , $FourIconsSet )}
|
||||
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddFiveIconSet( $Address , $FiveIconsSet )}
|
||||
else {$rule = ($Worksheet.ConditionalFormatting)."Add$RuleType"($Address ) }
|
||||
if ($Reverse) {
|
||||
if ($rule.type -match 'IconSet$' ) {$rule.reverse = $true}
|
||||
elseif ($rule.type -match 'ColorScale$') {$temp =$rule.LowValue.Color ; $rule.LowValue.Color = $rule.HighValue.Color; $rule.HighValue.Color = $temp}
|
||||
|
||||
@@ -49,7 +49,7 @@ function Add-ExcelChart {
|
||||
)
|
||||
try {
|
||||
if ($PivotTable) {
|
||||
$Worksheet = $PivotTable.WorkSheet
|
||||
$Worksheet = $PivotTable.Worksheet
|
||||
$chart = $Worksheet.Drawings.AddChart(("Chart" + $PivotTable.Name ), $ChartType, $PivotTable)
|
||||
}
|
||||
else {
|
||||
@@ -138,5 +138,5 @@ function Add-ExcelChart {
|
||||
|
||||
if ($PassThru) { return $chart }
|
||||
}
|
||||
catch { Write-Warning -Message "Failed adding Chart to worksheet '$($WorkSheet).name': $_" }
|
||||
catch { Write-Warning -Message "Failed adding Chart to worksheet '$($Worksheet).name': $_" }
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[Parameter(ValueFromPipeline = $true,Position=0)]
|
||||
[Alias("Address")]
|
||||
$Range ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
|
||||
[ValidateSet('Any','Custom','DateTime','Decimal','Integer','List','TextLength','Time')]
|
||||
$ValidationType,
|
||||
[OfficeOpenXml.DataValidation.ExcelDataValidationOperator]$Operator = [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]::equal ,
|
||||
@@ -28,13 +28,13 @@
|
||||
}
|
||||
else {
|
||||
#We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ]
|
||||
if (-not $WorkSheet -and $Range.worksheet) {$WorkSheet = $Range.worksheet}
|
||||
if (-not $Worksheet -and $Range.worksheet) {$Worksheet = $Range.worksheet}
|
||||
if ($Range.Address) {$Range = $Range.Address}
|
||||
|
||||
if ($Range -isnot [string] -or -not $WorkSheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return}
|
||||
if ($Range -isnot [string] -or -not $Worksheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return}
|
||||
#else we assume Range is a range.
|
||||
|
||||
$validation = $WorkSheet.DataValidations."Add$ValidationType`Validation"($Range)
|
||||
$validation = $Worksheet.DataValidations."Add$ValidationType`Validation"($Range)
|
||||
if ($validation.AllowsOperator) {$validation.Operator = $Operator}
|
||||
if ($PSBoundParameters.ContainsKey('value')) {
|
||||
$validation.Formula.Value = $Value
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
else {
|
||||
try {
|
||||
if (-not $ExcelPackage) {Write-Warning -message "This combination of Parameters needs to include the ExcelPackage." ; return }
|
||||
[OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-WorkSheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate
|
||||
[OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-Worksheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate
|
||||
if ($wsPivot.Name -ne $PivotTableName) {Write-Warning -Message "The Worksheet name for the PivotTable does not match the table name '$PivotTableName'; probably because excess or illegal characters were removed." }
|
||||
if ($PivotFilter) {$Address = $wsPivot.Cells["A3"]} else { $Address = $wsPivot.Cells["A1"]}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Function Compare-WorkSheet {
|
||||
Function Compare-Worksheet {
|
||||
[cmdletbinding(DefaultParameterSetName)]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
|
||||
@@ -49,7 +49,7 @@
|
||||
Catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return }
|
||||
|
||||
#Get Column headings and create a hash table of Name to column letter.
|
||||
$headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using get-member would sort them alphabetically!
|
||||
$headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using Get-member would sort them alphabetically!
|
||||
$headings | ForEach-Object -Begin {$columns = @{} ; $i= 1 } -Process {$Columns[$_] = [OfficeOpenXml.ExcelAddress]::GetAddress(1,($i ++)) -replace "\d","" }
|
||||
|
||||
#Make a list of property headings using the Property (default "*") and ExcludeProperty parameters
|
||||
@@ -88,13 +88,13 @@
|
||||
$ws = $xl.Workbook.Worksheets[$_]
|
||||
if ($headerName) {$range = "A" + $startrow + ":" + $ws.dimension.end.address}
|
||||
else {$range = "A" + ($startrow + 1) + ":" + $ws.dimension.end.address}
|
||||
Set-ExcelRange -WorkSheet $ws -BackgroundColor $AllDataBackgroundColor -Range $Range
|
||||
Set-ExcelRange -Worksheet $ws -BackgroundColor $AllDataBackgroundColor -Range $Range
|
||||
}
|
||||
}
|
||||
foreach ($row in $file.group) {
|
||||
$ws = $xl.Workbook.Worksheets[$row._Sheet]
|
||||
$range = $ws.Dimension -replace "\d+",$row._row
|
||||
Set-ExcelRange -WorkSheet $ws -Range $range -BackgroundColor $BackgroundColor
|
||||
Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $BackgroundColor
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey("TabColor")) {
|
||||
if ($TabColor -is [string]) {$TabColor = [System.Drawing.Color]::$TabColor }
|
||||
@@ -123,8 +123,8 @@
|
||||
$ws2 = $xl1.Workbook.Worksheets[$u.Group[1]._sheet]
|
||||
}
|
||||
if($u.Group[0].$p -ne $u.Group[1].$p ) {
|
||||
Set-ExcelRange -WorkSheet $ws1 -Range ($Columns[$p] + $u.Group[0]._Row) -FontColor $FontColor
|
||||
Set-ExcelRange -WorkSheet $ws2 -Range ($Columns[$p] + $u.Group[1]._Row) -FontColor $FontColor
|
||||
Set-ExcelRange -Worksheet $ws1 -Range ($Columns[$p] + $u.Group[0]._Row) -FontColor $FontColor
|
||||
Set-ExcelRange -Worksheet $ws2 -Range ($Columns[$p] + $u.Group[1]._Row) -FontColor $FontColor
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,11 @@ $myData = Get-Process | Select-Object -Property Name,WS,CPU,Description,c
|
||||
$excelPackage = $myData | Export-Excel -KillExcel -Path $Path -WorkSheetname $workSheetname -ClearSheet -AutoSize -AutoFilter -BoldTopRow -FreezeTopRow -PassThru
|
||||
$workSheet = $excelPackage.Workbook.Worksheets[$workSheetname]
|
||||
$range = $workSheet.Dimension.Address
|
||||
Set-ExcelRange -WorkSheet $workSheet -Range "b:b" -NumberFormat "#,###" -AutoFit
|
||||
Set-ExcelRange -WorkSheet $workSheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit
|
||||
Set-ExcelRange -WorkSheet $workSheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit
|
||||
Add-ConditionalFormatting -WorkSheet $workSheet -Range "c2:c1000" -DataBarColor Blue
|
||||
Add-ConditionalFormatting -WorkSheet $workSheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold
|
||||
Set-ExcelRange -Worksheet $workSheet -Range "b:b" -NumberFormat "#,###" -AutoFit
|
||||
Set-ExcelRange -Worksheet $workSheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit
|
||||
Set-ExcelRange -Worksheet $workSheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit
|
||||
Add-ConditionalFormatting -Worksheet $workSheet -Range "c2:c1000" -DataBarColor Blue
|
||||
Add-ConditionalFormatting -Worksheet $workSheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold
|
||||
|
||||
Export-Excel -ExcelPackage $excelPackage -WorkSheetname $workSheetname
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function Copy-ExcelWorkSheet {
|
||||
function Copy-ExcelWorksheet {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true,ValueFromPipeline=$true)]
|
||||
@@ -39,7 +39,7 @@
|
||||
return
|
||||
}
|
||||
else {
|
||||
$null = Add-WorkSheet -ExcelPackage $excel -WorkSheetname $DestinationWorksheet -CopySource ($excel.Workbook.Worksheets[$SourceWorkSheet])
|
||||
$null = Add-Worksheet -ExcelPackage $excel -WorkSheetname $DestinationWorksheet -CopySource ($excel.Workbook.Worksheets[$SourceWorkSheet])
|
||||
Close-ExcelPackage -ExcelPackage $excel -Show:$Show
|
||||
return
|
||||
}
|
||||
@@ -76,7 +76,7 @@
|
||||
$DestinationWorkbook.Worksheets.Delete($DestinationWorksheet)
|
||||
}
|
||||
Write-Verbose "Copying '$($sourcews.name)' from $($SourceObject) to '$($DestinationWorksheet)' in $($PSBoundParameters['DestinationWorkbook'])"
|
||||
$null = Add-WorkSheet -ExcelWorkbook $DestinationWorkbook -WorkSheetname $DestinationWorksheet -CopySource $sourceWs
|
||||
$null = Add-Worksheet -ExcelWorkbook $DestinationWorkbook -WorkSheetname $DestinationWorksheet -CopySource $sourceWs
|
||||
#Leave the destination open but close the source - if we're copying more than one sheet we'll re-open it and live with the inefficiency
|
||||
if ($stream) {$stream.Close() }
|
||||
if ($package1) {Close-ExcelPackage -ExcelPackage $package1 -NoSave }
|
||||
@@ -124,7 +124,7 @@
|
||||
try {
|
||||
$params = @{WorksheetName=$WorksheetName}
|
||||
foreach ($p in @("ClearSheet", "MoveToStart", "MoveToEnd", "MoveBefore", "MoveAfter", "Activate")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}}
|
||||
$ws = $pkg | Add-WorkSheet @params
|
||||
$ws = $pkg | Add-Worksheet @params
|
||||
if ($ws.Name -ne $WorksheetName) {
|
||||
Write-Warning -Message "The Worksheet name has been changed from $WorksheetName to $($ws.Name), this may cause errors later."
|
||||
$WorksheetName = $ws.Name
|
||||
@@ -609,27 +609,27 @@
|
||||
ForeGroundColor = $c.ConditionalTextColor}
|
||||
if ($c.Range) {$cfParams.Range = $c.Range}
|
||||
else {$cfParams.Range = $ws.Dimension.Address }
|
||||
Add-ConditionalFormatting -WorkSheet $ws @cfParams
|
||||
Add-ConditionalFormatting -Worksheet $ws @cfParams
|
||||
Write-Verbose -Message "Added conditional formatting to range $($c.range)"
|
||||
}
|
||||
elseif ($c.formatter) {
|
||||
switch ($c.formatter) {
|
||||
"ThreeIconSet" {Add-ConditionalFormatting -WorkSheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
"FourIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
"FiveIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
"ThreeIconSet" {Add-ConditionalFormatting -Worksheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
"FourIconSet" {Add-ConditionalFormatting -Worksheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
"FiveIconSet" {Add-ConditionalFormatting -Worksheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
|
||||
}
|
||||
Write-Verbose -Message "Added conditional formatting to range $($c.range)"
|
||||
}
|
||||
elseif ($c -is [hashtable] -or $c -is[System.Collections.Specialized.OrderedDictionary]) {
|
||||
if (-not $c.Range -or $c.Address) {$c.Address = $ws.Dimension.Address }
|
||||
Add-ConditionalFormatting -WorkSheet $ws @c
|
||||
Add-ConditionalFormatting -Worksheet $ws @c
|
||||
}
|
||||
}
|
||||
catch {throw "Error applying conditional formatting to worksheet $_"}
|
||||
}
|
||||
foreach ($s in $Style) {
|
||||
if (-not $s.Range) {$s["Range"] = $ws.Dimension.Address }
|
||||
Set-ExcelRange -WorkSheet $ws @s
|
||||
Set-ExcelRange -Worksheet $ws @s
|
||||
}
|
||||
if ($CellStyleSB) {
|
||||
try {
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
function Import-USPS {
|
||||
param(
|
||||
$TrackingNumber,
|
||||
[Switch]$UseDefaultCredentials
|
||||
|
||||
)
|
||||
|
||||
Import-Html "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=$($TrackingNumber)" 0 -UseDefaultCredentials: $UseDefaultCredentials
|
||||
}
|
||||
|
||||
function Import-UPS {
|
||||
function Import-UPS {
|
||||
param(
|
||||
$TrackingNumber,
|
||||
[Switch]$UseDefaultCredentials
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
function Import-USPS {
|
||||
|
||||
param(
|
||||
$TrackingNumber,
|
||||
[Switch]$UseDefaultCredentials
|
||||
|
||||
)
|
||||
|
||||
Import-Html "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=$($TrackingNumber)" 0 -UseDefaultCredentials: $UseDefaultCredentials
|
||||
Import-Html "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=$($TrackingNumber)" 0 -UseDefaultCredentials:$UseDefaultCredentials
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
)
|
||||
#region get target worksheet, select it and move it to the end.
|
||||
if ($Path -and -not $ExcelPackage) {$ExcelPackage = Open-ExcelPackage -path $Path }
|
||||
$destinationSheet = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname $WorkSheetName -ClearSheet:$Clearsheet
|
||||
$destinationSheet = Add-Worksheet -ExcelPackage $ExcelPackage -WorkSheetname $WorkSheetName -ClearSheet:$Clearsheet
|
||||
foreach ($w in $ExcelPackage.Workbook.Worksheets) {$w.view.TabSelected = $false}
|
||||
$destinationSheet.View.TabSelected = $true
|
||||
$ExcelPackage.Workbook.Worksheets.MoveToEnd($WorkSheetName)
|
||||
@@ -117,7 +117,7 @@
|
||||
if ($HideSource) {$sourceWorksheet.Hidden = [OfficeOpenXml.eWorkSheetHidden]::Hidden}
|
||||
}
|
||||
|
||||
#We accept a bunch of parameters work to pass on to Export-excel ( Autosize, Autofilter, boldtopRow Freeze ); if we have any of those call export-excel otherwise close the package here.
|
||||
#We accept a bunch of parameters work to pass on to Export-excel ( Autosize, Autofilter, boldtopRow Freeze ); if we have any of those call Export-excel otherwise close the package here.
|
||||
$params = @{} + $PSBoundParameters
|
||||
'Path', 'Clearsheet', 'NoHeader', 'FromLabel', 'LabelBlocks', 'HideSource',
|
||||
'Title', 'TitleFillPattern', 'TitleBackgroundColor', 'TitleBold', 'TitleSize' | ForEach-Object {$null = $params.Remove($_)}
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
#Make a list of properties/headings using the Property (default "*") and ExcludeProperty parameters
|
||||
$propList = @()
|
||||
$DifferenceObject = $DifferenceObject | Update-FirstObjectProperties
|
||||
$headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using get-member would sort them alphabetically! There may be extra properties in
|
||||
$headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using Get-member would sort them alphabetically! There may be extra properties in
|
||||
if ($NoHeader -and "Name" -eq $Key) {$Key = "p1"}
|
||||
if ($headings -notcontains $Key -and
|
||||
('*' -ne $Key)) {Write-Warning -Message "You need to specify one of the headings in the sheet '$Worksheet1' as a key." ; return }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Function Remove-WorkSheet {
|
||||
Function Remove-Worksheet {
|
||||
[cmdletbinding(SupportsShouldProcess=$true)]
|
||||
param(
|
||||
# [Parameter(ValueFromPipelineByPropertyName)]
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
Process {
|
||||
if (!$FullName) {
|
||||
throw "Remove-WorkSheet requires the and Excel file"
|
||||
throw "Remove-Worksheet requires the and Excel file"
|
||||
}
|
||||
|
||||
$pkg = Open-ExcelPackage -Path $FullName
|
||||
@@ -3,14 +3,14 @@ param()
|
||||
|
||||
function Set-CellStyle {
|
||||
param(
|
||||
$WorkSheet,
|
||||
$Worksheet,
|
||||
$Row,
|
||||
$LastColumn,
|
||||
[OfficeOpenXml.Style.ExcelFillStyle]$Pattern,
|
||||
$Color
|
||||
)
|
||||
if ($Color -is [string]) {$Color = [System.Drawing.Color]::$Color }
|
||||
$t=$WorkSheet.Cells["A$($Row):$($LastColumn)$($Row)"]
|
||||
$t=$Worksheet.Cells["A$($Row):$($LastColumn)$($Row)"]
|
||||
$t.Style.Fill.PatternType=$Pattern
|
||||
$t.Style.Fill.BackgroundColor.SetColor($Color)
|
||||
}
|
||||
@@ -116,7 +116,7 @@
|
||||
}
|
||||
if ($params.Count) {
|
||||
$theRange = "$columnName$StartRow`:$columnName$endRow"
|
||||
Set-ExcelRange -WorkSheet $Worksheet -Range $theRange @params
|
||||
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
|
||||
}
|
||||
#endregion
|
||||
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Column($Column).Hidden = [bool]$Hide}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[Parameter(ValueFromPipeline = $true,Position=0)]
|
||||
[Alias("Address")]
|
||||
$Range ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
|
||||
[Alias("NFormat")]
|
||||
$NumberFormat,
|
||||
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround,
|
||||
@@ -54,8 +54,8 @@
|
||||
else {
|
||||
#We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ]
|
||||
if ($Range -is [OfficeOpenXml.Table.ExcelTable]) {$Range = $Range.Address}
|
||||
elseif ($WorkSheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) {
|
||||
$Range = $WorkSheet.Cells[$Range]
|
||||
elseif ($Worksheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) {
|
||||
$Range = $Worksheet.Cells[$Range]
|
||||
}
|
||||
elseif ($Range -is [string]) {Write-Warning -Message "The range pararameter you have specified also needs a worksheet parameter." ;return}
|
||||
#else we assume $Range is a range.
|
||||
@@ -159,7 +159,7 @@
|
||||
if ($Range -is [OfficeOpenXml.ExcelRow] ) {$Range.Height = $Height }
|
||||
elseif ($Range -is [OfficeOpenXml.ExcelRange] ) {
|
||||
($Range.Start.Row)..($Range.Start.Row + $Range.Rows) |
|
||||
ForEach-Object {$Range.WorkSheet.Row($_).Height = $Height }
|
||||
ForEach-Object {$Range.Worksheet.Row($_).Height = $Height }
|
||||
}
|
||||
else {Write-Warning -Message ("Can set the height of a row or a range but not a {0} object" -f ($Range.GetType().name)) }
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
}
|
||||
if ($params.Count) {
|
||||
$theRange = New-Object -TypeName OfficeOpenXml.ExcelAddress @($Row, $StartColumn, $Row, $endColumn)
|
||||
Set-ExcelRange -WorkSheet $Worksheet -Range $theRange @params
|
||||
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
|
||||
}
|
||||
#endregion
|
||||
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Row($Row).Hidden = [bool]$Hide}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
Function Set-WorkSheetProtection {
|
||||
Function Set-WorksheetProtection {
|
||||
[Cmdletbinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
|
||||
[switch]$IsProtected,
|
||||
[switch]$AllowAll,
|
||||
[switch]$BlockSelectLockedCells,
|
||||
@@ -44,12 +44,12 @@
|
||||
Else {Write-Warning -Message "You haven't said if you want to turn protection off, or on." }
|
||||
|
||||
if ($LockAddress) {
|
||||
Set-ExcelRange -Range $WorkSheet.cells[$LockAddress] -Locked
|
||||
Set-ExcelRange -Range $Worksheet.cells[$LockAddress] -Locked
|
||||
}
|
||||
elseif ($IsProtected) {
|
||||
Set-ExcelRange -Range $WorkSheet.Cells -Locked
|
||||
Set-ExcelRange -Range $Worksheet.Cells -Locked
|
||||
}
|
||||
if ($UnlockAddress) {
|
||||
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked:$false
|
||||
Set-ExcelRange -Range $Worksheet.cells[$UnlockAddress] -Locked:$false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user