#Excelファイルのパス
$excelFilePath = "C:\Path\To\Your\File.xlsx"
#Excelファイルを開く
$excel = New-Object -ComObject Excel.Application
$excel.Visible = True
$excel.ScreenUpdating = False
$workbook = $excel.Workbooks.Open($excelFilePath)
$textFileBaseName = Split-Path -Path $excelFilePath -Leaf
$textFilePath = $textFileBaseName + ".txt"
#各シートをテキストファイルにコピー
foreach ($sheet in $workbook.Sheets) {
$sheetName = $sheet.Name
$usedRangeValue = $sheet.UsedRange.Value
$text = ""
foreach ($row in $usedRangeValue) {
$text += ($row -join "`t") + "`n"
}
Add-Content -Path $textFilePath -Value $text -Append
}
#Excelファイルを閉じる
$workbook.Close()
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($sheet)
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme