mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-01-07 19:13:43 +00:00
New tests for import -asText and send-SQL -Force
This commit is contained in:
@@ -16,6 +16,9 @@ Describe "Exporting with -Inputobject" {
|
||||
export-excel -Path $path -InputObject $results -WorksheetName Sheet1 -RangeName "Whole"
|
||||
export-excel -Path $path -InputObject $DataTable -WorksheetName Sheet2 -AutoNameRange
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet3 -TableName "Data"
|
||||
$DataTable.Rows.Clear()
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet4 -force
|
||||
Send-SQLDataToExcel -path $path -DataTable ([System.Data.DataTable]::new('Test2')) -WorkSheetname Sheet5 -force
|
||||
$excel = Open-ExcelPackage $path
|
||||
$sheet = $excel.Sheet1
|
||||
}
|
||||
@@ -60,7 +63,7 @@ Describe "Exporting with -Inputobject" {
|
||||
}
|
||||
$sheet = $excel.Sheet3
|
||||
Context "Table of processes via Send-SQLDataToExcel" {
|
||||
it "Put the correct rows and columns into the sheet " {
|
||||
it "Put the correct data rows and columns into the sheet " {
|
||||
$sheet.Dimension.Rows | should be ($results.Count + 1)
|
||||
$sheet.Dimension.Columns | should be 5
|
||||
$sheet.cells["A1"].Value | should be "Name"
|
||||
@@ -76,4 +79,29 @@ Describe "Exporting with -Inputobject" {
|
||||
$sheet.Cells["E11"].Style.Numberformat.NumFmtID | should be 22
|
||||
}
|
||||
}
|
||||
$Sheet = $excel.Sheet4
|
||||
Context "Zero row Data Table sent with Send-SQLDataToExcel -Force" {
|
||||
it "Put the correct data headers into the sheet " {
|
||||
$sheet.Dimension.Rows | should be 1
|
||||
$sheet.Dimension.Columns | should be 5
|
||||
$sheet.cells["A1"].Value | should be "Name"
|
||||
$sheet.cells["E1"].Value | should be "StartTime"
|
||||
$sheet.cells["A3"].Value | should beNullOrEmpty
|
||||
}
|
||||
}
|
||||
$Sheet = $excel.Sheet5
|
||||
Context "Zero column data table handled by Send-SQLDataToExcel -Force" {
|
||||
it "Put Created a blank Sheet " {
|
||||
$sheet.Dimension | should beNullOrEmpty
|
||||
}
|
||||
}
|
||||
Close-ExcelPackage $excel
|
||||
Context "Import As Text returns text values" {
|
||||
$x = import-excel $path -WorksheetName sheet3 -AsText | Select-Object -last 1
|
||||
it "Had fields of type string, not date or int " {
|
||||
$x.Handles.GetType().Name | should be "String"
|
||||
$x.StartTime.GetType().Name | should be "String"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -323,36 +323,36 @@ Describe "AutoNameRange data with a single property name" {
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
it "Should have a single item as a named range" {
|
||||
$excel = ConvertFrom-Csv @"
|
||||
it "Should have a single item as a named range " {
|
||||
$excel = ConvertFrom-Csv @"
|
||||
Sold
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
"@ | Export-Excel $xlfile -PassThru -AutoNameRange
|
||||
"@ | Export-Excel $xlfile -PassThru -AutoNameRange
|
||||
|
||||
$ws = $excel.Workbook.Worksheets["Sheet1"]
|
||||
$ws = $excel.Workbook.Worksheets["Sheet1"]
|
||||
|
||||
$ws.Names.Count | Should Be 1
|
||||
$ws.Names[0].Name | Should Be 'Sold'
|
||||
}
|
||||
$ws.Names.Count | Should Be 1
|
||||
$ws.Names[0].Name | Should Be 'Sold'
|
||||
}
|
||||
|
||||
it "Should have a more than a single item as a named range" {
|
||||
$excel = ConvertFrom-Csv @"
|
||||
it "Should have a more than a single item as a named range " {
|
||||
$excel = ConvertFrom-Csv @"
|
||||
Sold,ID
|
||||
1,a
|
||||
2,b
|
||||
3,c
|
||||
4,d
|
||||
"@ | Export-Excel $xlfile -PassThru -AutoNameRange
|
||||
"@ | Export-Excel $xlfile -PassThru -AutoNameRange
|
||||
|
||||
$ws = $excel.Workbook.Worksheets["Sheet1"]
|
||||
$ws = $excel.Workbook.Worksheets["Sheet1"]
|
||||
|
||||
$ws.Names.Count | Should Be 2
|
||||
$ws.Names[0].Name | Should Be 'Sold'
|
||||
$ws.Names[1].Name | Should Be 'ID'
|
||||
}
|
||||
$ws.Names.Count | Should Be 2
|
||||
$ws.Names[0].Name | Should Be 'Sold'
|
||||
$ws.Names[1].Name | Should Be 'ID'
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Table Formatting" {
|
||||
|
||||
Reference in New Issue
Block a user