Rename helper function to make it more helpful. =)

This commit is contained in:
Roy Ashbrook
2021-11-04 10:44:14 -04:00
parent 5e7b404daf
commit 85f2433ffc
2 changed files with 7 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
#Requires -Version 5
function Read-XlsxUsingOleDb {
function Invoke-ExcelQuery {
<#
.SYNOPSIS
Helper method for executing Read-OleDbData with some basic defaults.
@@ -17,7 +17,7 @@ function Read-XlsxUsingOleDb {
-SqlStatement $Query
.EXAMPLE
Read-XlsxUsingOleDb .\test.xlsx 'select ROUND(F1) as [A1] from [sheet3$A1:A1]'
Invoke-ExcelQuery .\test.xlsx 'select ROUND(F1) as [A1] from [sheet3$A1:A1]'
.EXAMPLE
$Path = (Get-ChildItem 'test.xlsx').FullName
@@ -29,7 +29,7 @@ function Read-XlsxUsingOleDb {
Path = .\test.xlsx
Query = Get-Content query.sql -Raw
}
$Results = Read-XlsxUsingOleDb @ReadDataArgs
$Results = Invoke-ExcelQuery @ReadDataArgs
#>
param(
#The path to the file to open.
@@ -41,7 +41,7 @@ function Read-XlsxUsingOleDb {
[String] $Query # var name consistent with Invoke-Sqlcmd
)
$FullName = (Get-ChildItem $Path).FullName
Read-OleDbData `
Invoke-ExcelQuery `
-ConnectionString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$FullName;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" `
-SqlStatement $Query
}

View File

@@ -4,16 +4,16 @@ Import-Module $scriptPath\..\..\ImportExcel.psd1 -Force
$tfp = "$scriptPath\Read-OleDbData.xlsx"
$ACEnotWorking = $false
try {
$Results = Read-XlsxUsingOleDb $tfp "select 1"
$Results = Invoke-ExcelQuery $tfp "select 1"
}
catch {
$ACEnotWorking = $true
}
Describe "Read-XlsxUsingOleDb" -Tag "Read-XlsxUsingOleDb" {
Describe "Invoke-ExcelQuery" -Tag "Invoke-ExcelQuery" {
$PSDefaultParameterValues = @{ 'It:Skip' = $ACEnotWorking }
Context "Sheet1`$A1" {
It "Should return 1 result with a value of 1" {
$Results = Read-XlsxUsingOleDb $tfp "select ROUND(F1) as [A1] from [sheet1`$A1:A1]"
$Results = Invoke-ExcelQuery $tfp "select ROUND(F1) as [A1] from [sheet1`$A1:A1]"
@($Results).length + $Results.A1 | Should -Be 2
}
}