mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
WS protection & better control of export -now
This commit is contained in:
@@ -531,13 +531,13 @@
|
|||||||
try {
|
try {
|
||||||
$script:Header = $null
|
$script:Header = $null
|
||||||
if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet."}
|
if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet."}
|
||||||
|
#if we have no params, or explicit -now, or no path/package. Set a path, and set show/autosize/Autofilter if not set (they maybe passed as $false)
|
||||||
if ($PSBoundParameters.Keys.Count -eq 0 -Or $Now -or (-not $Path -and -not $ExcelPackage) ) {
|
if ($PSBoundParameters.Keys.Count -eq 0 -Or $Now -or (-not $Path -and -not $ExcelPackage) ) {
|
||||||
$Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx'
|
$Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx'
|
||||||
$Show = $true
|
if (-not $PSBoundParameters.ContainsKey('Show')) {$Show = $true}
|
||||||
$AutoSize = $true
|
if (-not $PSBoundParameters.ContainsKey('AutoSize')) {$AutoSize = $true}
|
||||||
if (-not $TableName) {
|
if (-not $PSBoundParameters.ContainsKey('AutoFilter') -and
|
||||||
$AutoFilter = $true
|
-not $TableName) {$AutoFilter = $true}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($ExcelPackage) {
|
if ($ExcelPackage) {
|
||||||
$pkg = $ExcelPackage
|
$pkg = $ExcelPackage
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
|
|||||||
'Set-ExcelColumn',
|
'Set-ExcelColumn',
|
||||||
'Set-ExcelRange',
|
'Set-ExcelRange',
|
||||||
'Set-ExcelRow',
|
'Set-ExcelRow',
|
||||||
|
'Set-WorkSheetProtection',
|
||||||
'Test-Boolean',
|
'Test-Boolean',
|
||||||
'Test-Date',
|
'Test-Date',
|
||||||
'Test-Integer',
|
'Test-Integer',
|
||||||
|
|||||||
@@ -25,6 +25,14 @@
|
|||||||
"WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc
|
"WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc
|
||||||
the new data cells should become a named range, which will also be
|
the new data cells should become a named range, which will also be
|
||||||
named "WinsToFastLaps" and the column width will be set automatically.
|
named "WinsToFastLaps" and the column width will be set automatically.
|
||||||
|
When a value begins with "=", it is treated as a formula.
|
||||||
|
If value is a script block it will be evaluated, so here the string "=E$row/C$Row"
|
||||||
|
will have the number of the current row inserted. See the value parameter for a list of
|
||||||
|
variables which can be used. Note than when evaluating an expression in a string,
|
||||||
|
it is necessary to wrap it in $() so $row is valid but $($row+1) is needed. To prevent
|
||||||
|
Variables merging into other parts of the string, use the back tick "$columnName`4" will
|
||||||
|
be "G4" - withouth the backtick the string will look for a variable named "columnName4"
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
|
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
.Example
|
.Example
|
||||||
Set-WorkSheetProtection -WorkSheet $planSheet -IsProtected -AllowAll -AllowInsertColumns:$false -AllowDeleteColumns:$false -UnLockAddress "A:N"
|
Set-WorkSheetProtection -WorkSheet $planSheet -IsProtected -AllowAll -AllowInsertColumns:$false -AllowDeleteColumns:$false -UnLockAddress "A:N"
|
||||||
Turns on protection for the worksheet in $planSheet, checks all the allow boxes excel Insert and Delete columns and unlocks columns A-N
|
Turns on protection for the worksheet in $planSheet, checks all the allow boxes except Insert and Delete columns and unlocks columns A-N
|
||||||
#>
|
#>
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
|
||||||
param (
|
param (
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
[switch]$BlockEditObject,
|
[switch]$BlockEditObject,
|
||||||
##Opposite of the value in the 'Edit Scenarios' check box. Set to allow when Protect is first enabled
|
##Opposite of the value in the 'Edit Scenarios' check box. Set to allow when Protect is first enabled
|
||||||
[switch]$BlockEditScenarios,
|
[switch]$BlockEditScenarios,
|
||||||
#Address range for cells to lock in the form "A:Z" or "1:10" or "A1:Z10"
|
#Address range for cells to lock in the form "A:Z" or "1:10" or "A1:Z10". If No range is specified, the whole sheet is locked by default.
|
||||||
[string]$LockAddress,
|
[string]$LockAddress,
|
||||||
#Address range for cells to Unlock in the form "A:Z" or "1:10" or "A1:Z10"
|
#Address range for cells to Unlock in the form "A:Z" or "1:10" or "A1:Z10"
|
||||||
[string]$UnLockAddress
|
[string]$UnLockAddress
|
||||||
@@ -72,10 +72,13 @@
|
|||||||
}
|
}
|
||||||
Else {Write-Warning -Message "You haven't said if you want to turn protection off, or on." }
|
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
|
||||||
|
}
|
||||||
|
elseif ($IsProtected) {
|
||||||
|
Set-ExcelRange -Range $WorkSheet.Cells -Locked
|
||||||
|
}
|
||||||
if ($UnlockAddress) {
|
if ($UnlockAddress) {
|
||||||
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked:$false
|
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked:$false
|
||||||
}
|
}
|
||||||
if ($lockAddress) {
|
|
||||||
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user