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 {
|
||||
$script:Header = $null
|
||||
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) ) {
|
||||
$Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx'
|
||||
$Show = $true
|
||||
$AutoSize = $true
|
||||
if (-not $TableName) {
|
||||
$AutoFilter = $true
|
||||
}
|
||||
if (-not $PSBoundParameters.ContainsKey('Show')) {$Show = $true}
|
||||
if (-not $PSBoundParameters.ContainsKey('AutoSize')) {$AutoSize = $true}
|
||||
if (-not $PSBoundParameters.ContainsKey('AutoFilter') -and
|
||||
-not $TableName) {$AutoFilter = $true}
|
||||
}
|
||||
if ($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-ExcelRange',
|
||||
'Set-ExcelRow',
|
||||
'Set-WorkSheetProtection',
|
||||
'Test-Boolean',
|
||||
'Test-Date',
|
||||
'Test-Integer',
|
||||
|
||||
@@ -25,6 +25,14 @@
|
||||
"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
|
||||
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
|
||||
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
.Example
|
||||
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')]
|
||||
param (
|
||||
@@ -48,7 +48,7 @@
|
||||
[switch]$BlockEditObject,
|
||||
##Opposite of the value in the 'Edit Scenarios' check box. Set to allow when Protect is first enabled
|
||||
[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,
|
||||
#Address range for cells to Unlock in the form "A:Z" or "1:10" or "A1:Z10"
|
||||
[string]$UnLockAddress
|
||||
@@ -72,10 +72,13 @@
|
||||
}
|
||||
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) {
|
||||
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked:$false
|
||||
}
|
||||
if ($lockAddress) {
|
||||
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user