【问题标题】:Exporting query result to the excel sheet using powershell使用powershell将查询结果导出到excel表
【发布时间】:2017-05-29 09:29:15
【问题描述】:

我写了一个函数Ge​​t-oracleresultDa,它具有oracle连接属性。通过它我可以查询我的数据库。

但是,问题是我尝试将数据导出到 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 行中

$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

我还有几个要导出的查询

【问题讨论】:

    标签: excel powershell


    【解决方案1】:

    如果你使用powershell 3.0或更高版本,可以使用-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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多