mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Rename helper function to make it more helpful. =)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#Requires -Version 5
|
#Requires -Version 5
|
||||||
function Read-XlsxUsingOleDb {
|
function Invoke-ExcelQuery {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Helper method for executing Read-OleDbData with some basic defaults.
|
Helper method for executing Read-OleDbData with some basic defaults.
|
||||||
@@ -17,7 +17,7 @@ function Read-XlsxUsingOleDb {
|
|||||||
-SqlStatement $Query
|
-SqlStatement $Query
|
||||||
|
|
||||||
.EXAMPLE
|
.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
|
.EXAMPLE
|
||||||
$Path = (Get-ChildItem 'test.xlsx').FullName
|
$Path = (Get-ChildItem 'test.xlsx').FullName
|
||||||
@@ -29,7 +29,7 @@ function Read-XlsxUsingOleDb {
|
|||||||
Path = .\test.xlsx
|
Path = .\test.xlsx
|
||||||
Query = Get-Content query.sql -Raw
|
Query = Get-Content query.sql -Raw
|
||||||
}
|
}
|
||||||
$Results = Read-XlsxUsingOleDb @ReadDataArgs
|
$Results = Invoke-ExcelQuery @ReadDataArgs
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
#The path to the file to open.
|
#The path to the file to open.
|
||||||
@@ -41,7 +41,7 @@ function Read-XlsxUsingOleDb {
|
|||||||
[String] $Query # var name consistent with Invoke-Sqlcmd
|
[String] $Query # var name consistent with Invoke-Sqlcmd
|
||||||
)
|
)
|
||||||
$FullName = (Get-ChildItem $Path).FullName
|
$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;'" `
|
-ConnectionString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$FullName;Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=1;'" `
|
||||||
-SqlStatement $Query
|
-SqlStatement $Query
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,16 @@ Import-Module $scriptPath\..\..\ImportExcel.psd1 -Force
|
|||||||
$tfp = "$scriptPath\Read-OleDbData.xlsx"
|
$tfp = "$scriptPath\Read-OleDbData.xlsx"
|
||||||
$ACEnotWorking = $false
|
$ACEnotWorking = $false
|
||||||
try {
|
try {
|
||||||
$Results = Read-XlsxUsingOleDb $tfp "select 1"
|
$Results = Invoke-ExcelQuery $tfp "select 1"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$ACEnotWorking = $true
|
$ACEnotWorking = $true
|
||||||
}
|
}
|
||||||
Describe "Read-XlsxUsingOleDb" -Tag "Read-XlsxUsingOleDb" {
|
Describe "Invoke-ExcelQuery" -Tag "Invoke-ExcelQuery" {
|
||||||
$PSDefaultParameterValues = @{ 'It:Skip' = $ACEnotWorking }
|
$PSDefaultParameterValues = @{ 'It:Skip' = $ACEnotWorking }
|
||||||
Context "Sheet1`$A1" {
|
Context "Sheet1`$A1" {
|
||||||
It "Should return 1 result with a value of 1" {
|
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
|
@($Results).length + $Results.A1 | Should -Be 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user