mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-01-06 18:43:25 +00:00
First pass. All code must be in a script block
This commit is contained in:
@@ -1,31 +1,27 @@
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
||||
param()
|
||||
$data = ConvertFrom-Csv -InputObject @"
|
||||
ID,Product,Quantity,Price
|
||||
12001,Nails,37,3.99
|
||||
12002,Hammer,5,12.10
|
||||
12003,Saw,12,15.37
|
||||
12010,Drill,20,8
|
||||
12011,Crowbar,7,23.48
|
||||
"@
|
||||
|
||||
$path = "TestDrive:\DataValidation.xlsx"
|
||||
|
||||
Describe "Data validation and protection" {
|
||||
Context "Data Validation rules" {
|
||||
BeforeAll {
|
||||
$data = ConvertFrom-Csv -InputObject @"
|
||||
ID,Product,Quantity,Price
|
||||
12001,Nails,37,3.99
|
||||
12002,Hammer,5,12.10
|
||||
12003,Saw,12,15.37
|
||||
12010,Drill,20,8
|
||||
12011,Crowbar,7,23.48
|
||||
"@
|
||||
$path = "TestDrive:\DataValidation.xlsx"
|
||||
Remove-Item $path -ErrorAction SilentlyContinue
|
||||
$excelPackage = $Data | Export-excel -WorksheetName "Sales" -path $path -PassThru
|
||||
$excelPackage = @('Chisel','Crowbar','Drill','Hammer','Nails','Saw','Screwdriver','Wrench') |
|
||||
Export-excel -ExcelPackage $excelPackage -WorksheetName Values -PassThru
|
||||
$excelPackage = $Data | Export-excel -WorksheetName "Sales" -path $path -PassThru
|
||||
$excelPackage = @('Chisel', 'Crowbar', 'Drill', 'Hammer', 'Nails', 'Saw', 'Screwdriver', 'Wrench') |
|
||||
Export-excel -ExcelPackage $excelPackage -WorksheetName Values -PassThru
|
||||
|
||||
$VParams = @{Worksheet = $excelPackage.sales; ShowErrorMessage=$true; ErrorStyle='stop'; ErrorTitle='Invalid Data' }
|
||||
$VParams = @{Worksheet = $excelPackage.sales; ShowErrorMessage = $true; ErrorStyle = 'stop'; ErrorTitle = 'Invalid Data' }
|
||||
Add-ExcelDataValidationRule @VParams -Range 'B2:B1001' -ValidationType List -Formula 'values!$a$1:$a$10' -ErrorBody "You must select an item from the list.`r`nYou can add to the list on the values page" #Bucket
|
||||
Add-ExcelDataValidationRule @VParams -Range 'E2:E1001' -ValidationType Integer -Operator between -Value 0 -Value2 10000 -ErrorBody 'Quantity must be a whole number between 0 and 10000'
|
||||
Close-ExcelPackage -ExcelPackage $excelPackage
|
||||
|
||||
$excelPackage = Open-ExcelPackage -Path $path
|
||||
$ws = $excelPackage.Sales
|
||||
$ws = $excelPackage.Sales
|
||||
}
|
||||
It "Created the expected number of rules " {
|
||||
$ws.DataValidations.count | Should -Be 2
|
||||
|
||||
Reference in New Issue
Block a user