forked from dfinke/ImportExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export-Excel.Tests.ps1
64 lines (51 loc) · 1.54 KB
/
Export-Excel.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Contributed by https://github.com/W1M0R
Import-Module ImportExcel -Force
function New-TestWorkbook {
$testWorkbook = "$($PSScriptRoot)\test.xlsx"
Remove-Item $testWorkbook -ErrorAction Ignore
$testWorkbook
}
function Remove-TestWorkbook {
New-TestWorkbook | Out-Null
}
function New-TestDataCsv {
@"
ID,Product,Quantity,Price,Total
12001,Nails,37,3.99,147.63
12002,Hammer,5,12.10,60.5
12003,Saw,12,15.37,184.44
01200,Drill,20,8,160
00120,Crowbar,7,23.48,164.36
true,Bla,7,82,12
false,Bla,7,82,12
2009-05-01 14:57:32.8,Yay,1,3,2
"@ | ConvertFrom-Csv
}
Describe "Export-Excel" {
$csvData = New-TestDataCsv
$workbook = New-TestWorkbook
Context "Importing CSV data from a here string" {
It "All properties are type [string]" {
$csvData | % {
$_.PSObject.Properties | % {
$_.Value -is [string] | Should Be $true
}
}
}
It "Leading zeroes are preserved" {
$csvData[4] | Select-Object -ExpandProperty ID | Should Be "00120"
}
}
Context "Piping CSV data to Export-Excel" {
$xlPkg = $csvData | Export-Excel $workbook -PassThru
$ws = $xlPkg.Workbook.WorkSheets[1]
It "Exports numeric strings as numbers" {
$csvData[2] | Select-Object -ExpandProperty ID | Should Be "12003"
$ws.Cells["A4"].Value -is [double] | Should Be $true
$ws.Cells["A4"].Value | Should Be 12003
}
$xlPkg.Save()
$xlPkg.Dispose()
}
Remove-TestWorkbook
}