gpt4 book ai didi

powershell - 使用Powershell将accdb转换为csv

转载 作者:行者123 更新时间:2023-12-03 00:54:53 25 4
gpt4 key购买 nike

我正在尝试将一些Excel(.xlsx)和Access(.accdb)转换为CSV文件。

我很快找到了一种使用Excel进行此操作的方法,但现在找不到关于转换.accdb文件的任何有用的文档。

到目前为止,我有:

        $adOpenStatic = 3
$adLockOptimistic = 3

$objConnection = New-Object -com "ADODB.Connection"
$objRecordSet = New-Object -com "ADODB.Recordset"


$objConnection.Open("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + $Filepath)
$objRecordset.Open("Select * From TableName",$objConnection,$adOpenStatic, $adLockOptimistic)

#Here I need some way to either saveas .csv or loop through
#each row and pass to csv.

$objRecordSet.Close()
$objConnection.Close()

有任何想法吗?

如果有人知道的话,我愿意用另一种语言(VB,Java,PHP)来做。

最佳答案

如果要坚持使用ADODB COM对象:

# loop through all records - do work on each record to convert it to CSV
$objRecordset.Open("Select * FROM Tablename", $objConnection,$adOpenStatic,$adLockOptimistic)

$objRecordset.MoveFirst()

do {
# do your work to get each field and convert this item to CSV
# fields available thru: $objRecordset.Fields['fieldname'].Value
$objRecordset.MoveNext()

} while ($objRecordset.EOF -eq $false)

$objRecordset.Close()

关于powershell - 使用Powershell将accdb转换为csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5710375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com