mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merge pull request #296 from jhoneill/master
SQL Server related bug fixes in Send-SQLDataToExcel.ps1
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
[switch]$MsSQLserver,
|
[switch]$MsSQLserver,
|
||||||
#Switches to a specific database on a SQL server
|
#Switches to a specific database on a SQL server
|
||||||
[Parameter(ParameterSetName="SQLConnection")]
|
[Parameter(ParameterSetName="SQLConnection")]
|
||||||
[switch]$DataBase,
|
[String]$DataBase,
|
||||||
#The SQL query to run
|
#The SQL query to run
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$SQL,
|
[string]$SQL,
|
||||||
@@ -94,6 +94,7 @@
|
|||||||
if ($MsSQLserver) {
|
if ($MsSQLserver) {
|
||||||
if ($connection -notmatch "=") {$Connection = "server=$Connection;trusted_connection=true;timeout=60"}
|
if ($connection -notmatch "=") {$Connection = "server=$Connection;trusted_connection=true;timeout=60"}
|
||||||
$Session = New-Object -TypeName System.Data.SqlClient.SqlConnection -ArgumentList $Connection
|
$Session = New-Object -TypeName System.Data.SqlClient.SqlConnection -ArgumentList $Connection
|
||||||
|
if ($Session.State -ne 'Open') {$session.Open()}
|
||||||
if ($DataBase) {$Session.ChangeDatabase($DataBase) }
|
if ($DataBase) {$Session.ChangeDatabase($DataBase) }
|
||||||
}
|
}
|
||||||
elseif ($Connection) {
|
elseif ($Connection) {
|
||||||
@@ -124,7 +125,7 @@
|
|||||||
$excelPackage.Workbook.Worksheets[$WorkSheetname].Cells[$r,$StartColumn].LoadFromDataTable($dataTable, $PrintHeaders ) | Out-Null
|
$excelPackage.Workbook.Worksheets[$WorkSheetname].Cells[$r,$StartColumn].LoadFromDataTable($dataTable, $PrintHeaders ) | Out-Null
|
||||||
|
|
||||||
#Call export-excel with any parameters which don't relate to the SQL query
|
#Call export-excel with any parameters which don't relate to the SQL query
|
||||||
"Connection", "Session", "MsSQLserver", "Destination" , "sql" ,"Path" | foreach-object {$null = $PSBoundParameters.Remove($_) }
|
"Connection", "Database" , "Session", "MsSQLserver", "Destination" , "sql" ,"Path" | foreach-object {$null = $PSBoundParameters.Remove($_) }
|
||||||
Export-Excel -ExcelPackage $excelPackage @PSBoundParameters
|
Export-Excel -ExcelPackage $excelPackage @PSBoundParameters
|
||||||
|
|
||||||
#If we were not passed a session close the session we created.
|
#If we were not passed a session close the session we created.
|
||||||
|
|||||||
Reference in New Issue
Block a user