我又想验证一下,又使用ChatGPT阅读了上面的错误信息,给出的正确答案:- $connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='鸟种数据导出.xlsx';Extended Properties='Excel 12.0 Xml;HDR=YES';"
- $dataTable = New-Object System.Data.DataTable
- $adapter = New-Object System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [鸟种数据导出$]", $connection)
- $adapter.Fill($dataTable) | Out-Null
-
- $outputFile = "1.txt"
- $startingRow = 2
-
- for ($i = $startingRow - 1; $i -lt $dataTable.Rows.Count; $i++) {
- $value = $dataTable.Rows[$i][1] # 第二列为索引 1
- $value | Out-File -FilePath $outputFile -Append -Encoding UTF8
- }
复制代码
- $connection="Provider=Microsoft.ACE.OLEDB.12.0;Data Source='鸟种数据导出.xlsx';Extended Properties='Excel 12.0 Xml;HDR=YES';";$dataTable=New-Object System.Data.DataTable;(New-Object System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [鸟种数据导出$]",$connection)).Fill($dataTable)|Out-Null;$outputFile="1.txt";$startingRow=2;for($i=$startingRow-1;$i -lt $dataTable.Rows.Count;$i++){$value=$dataTable.Rows[$i][1];$value|Out-File -FilePath $outputFile -Append -Encoding UTF8;}
复制代码
- powershell -c "$connection='Provider=Microsoft.ACE.OLEDB.12.0;Data Source=''鸟种数据导出.xlsx'';Extended Properties=''Excel 12.0 Xml;HDR=YES''';$dataTable=New-Object System.Data.DataTable;(New-Object System.Data.OleDb.OleDbDataAdapter('SELECT * FROM [鸟种数据导出$]',$connection)).Fill($dataTable)|Out-Null;$outputFile='1.txt';$startingRow=2;for($i=$startingRow-1;$i -lt $dataTable.Rows.Count;$i++){$value=$dataTable.Rows[$i][1];$value|Out-File -FilePath $outputFile -Append -Encoding UTF8;}"
复制代码 三种方式,我都测试了一下,测试通过了。 |