0
我必須使用大量的文本文件。我能夠將這些文件整合到一個文件中。但是我也在我的工作中使用了文件名,我希望在文件本身的文本之前以excel格式存在,最好第一列應該包含文件的名稱,然後列可以包含數據。用於整合文件的Windows腳本
任何幫助,將不勝感激。謝謝。
我必須使用大量的文本文件。我能夠將這些文件整合到一個文件中。但是我也在我的工作中使用了文件名,我希望在文件本身的文本之前以excel格式存在,最好第一列應該包含文件的名稱,然後列可以包含數據。用於整合文件的Windows腳本
任何幫助,將不勝感激。謝謝。
這是Powershell腳本。您可能需要稍作修改,以查找特定的文件擴展名現在只要找PS1文件
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object System.Globalization.CultureInfo("en-US")
$excel = new-Object -comobject Excel.Application
$excel.visible = $false
$workBook = $excel.Workbooks.Add()
$sheet = $workBook.Sheets.Item(1)
$sheet.Name = "Files"
$sheet.Range("A1", "B1").Font.Bold = $true
$sheet.Range("A1","A2").ColumnWidth = 40
$sheet.Range("B1","B2").ColumnWidth = 100
$sheet.Cells.Item(1,1) = "Filename"
$sheet.cells.Item(1,2) = "Content"
$files = get-childitem C:\PST -recurse | where {$_.extension -eq ".ps1"}
$index = 2
foreach($file in $files)
{
$sheet.Cells.Item($index,1) = $file.FullName
$sheet.Cells.Item($index,2) = [System.IO.File]::ReadAllText($file.FullName)
$index++
}
$workBook.SaveAs("C:\PST\1.xlsx")
$excel.Quit()
注:我不會假裝它是完美的,你仍然需要打磨,並重構它,但至少它會給你指示
$ workBook.SaveAs(「C:\ PST \ 1.xlsx」)或$ workBook.SaveAs(「C:\ PST \ 1.xls」),基於Office版本安裝! –
你想使用哪種程序員語言? – reporter
Windows腳本。我有Powershell – user1061514
發佈您的實際腳本。這是嘗試幫助你的起點。 –