2016-05-25 1 views
0

私はゆっくりとPower shellを使用しています。私は新しい「.txt」ファイルに保存したい列式を持ついくつかのExcelファイル(500+)を持っています。私はすでに、特定のフォルダ上でファイルを1つずつ検索するスクリプトを作成しました。今私の質問は、どのようにExcelのテキストファイルに列の範囲をコピーすることができます。ここexcelからtxtファイルまでの範囲の行をコピーするには

私が働いていたものです:あなたは新しいExcelファイルにデータを貼り付ける及び.txtとして保存でき

#Set the start and end range of the Formula column 
$NewMax = $sheet.UsedRange.Rows.Count 

$FormulaRange = $Sheet.range("G5:G$NewMax") 
$FormulaRange.Copy() | out-null 

答えて

0

、ここでのテストは、私が上陸したソリューションです:

$FormulaRange.Copy() 

がこれを行う

#Set the start and end range of the Formula column 
$NewMax = $sheet.UsedRange.Rows.Count 

$FormulaRange = $Sheet.range("AQ6:AQ$NewMax") 
$FormulaRange | select text | Export-Csv "c:\\output\sample.txt" -NoTypeInformation 
(Get-Content "c:\\output\sample.txt") | % {$_ -replace '"', ""} | out-file -FilePath "c:\\output\sample.txt" -Force -Encoding ascii 

最初に私が選択した範囲をエクスポート.txt拡張子で保存したcsvファイルにコピーします。次に、replace関数を使って各行の引用符を削除しました。

0

。あなたの後

:いくつかのグーグル後

$wb = $app.Workbooks.Add() 
$ws = $wb.Worksheets(1) 
$ws.Paste() 
$app.DisplayAlerts = $False 
$wb.SaveAs("C:\Users\admin\Desktop\Book2.txt", -4158) # xlText 
$wb.Close($False) 
$app.DisplayAlerts = $True 
+0

これは動作しますが、すべての行に引用符が残ります。 –

関連する問題