2017-05-28 522 views
0

我寫了一個具有oracle連接屬性的函數Get-oracleresultDa。通過它我可以查詢我的數據庫。使用powershell將查詢結果導出到excel表格

但是,問題是,我嘗試將數據導出到Excel工作表它只返回所述第二查詢即的結果)沒有狀態 而不是沒有類型

$results = Get-OracleResultDa -conString $connectionString -sqlString $query 
-Verbose 
$results | SELECT no, type| Export-CSV "H:\Book2.csv" -Force 
$rows++ 
$results1 = Get-OracleResultDa -conString $connectionString -sqlString 
$created -Verbose 
$results1 | SELECT no, status| Export-CSV "H:\Book2.csv" - 
NoTypeInformation 

下面提到的塊是在第10 linesof腳本

$file="H:\Book2.csv" 
$excel = New-Object -ComObject excel.application 
#Makes Excel Visable 
$excel.Application.Visible = $true 
$excel.DisplayAlerts = $false 
#Creates Excel workBook 
$book = $excel.Workbooks.Add() 
#Adds worksheets 

#gets the work sheet and Names it 
$sheet = $book.Worksheets.Item(1) 
$sheet.name = 'Created' 
#Select a worksheet 
$sheet.Activate() | Out-Null 

我有幾多個查詢的還因爲如果你使用PowerShell 3.0或貝特要出口

回答

1

r,您可以使用-Append修飾符

$results = Get-OracleResultDa -conString $connectionString -sqlString $query 
-Verbose 
$results | SELECT no, type| Export-CSV "H:\Book2.csv" -Force 
$rows++ 



$results1 = Get-OracleResultDa -conString $connectionString -sqlString 
$created -Verbose 
$results1 | SELECT no, status| Export-CSV "H:\Book2.csv" - 
NoTypeInformation -Append