if ( $args -eq $null ) { Write-Error '引数がありません' } if (Test-Path $args[0]) { $excel = New-Object -ComObject Excel.Application $excel.Visible = $false try { $book = $excel.Workbooks.Open($args[0]) $sheet = $book.Sheets('Sheet1') # シート数 $book.Sheets.Count # 一番目のシート名 $book.Sheets(1).Name # アクティブシート名 $book.ActiveSheet.Name $sheet.Cells($row, $col) $sheet.Range($sheet.Cells($row, $col), $sheet.Cells($row, $col)) # テキスト(単一セルのみ) $sheet.Range("範囲").Text # 数式(単一セルのみ) $sheet.Range("範囲").Formula # テキスト(単一・複数セル) $sheet.Range("範囲").Value() # 上書き保存 $book.Save() # 別名保存 $book.SaveAs("test.xlsx") # CSV $book.SaveAs("test.csv", 6) # UTF8 CSV $book.SaveAs("test.csv", 62) # Windows CSV $book.SaveAs("test.csv", 23) # Windows テキスト $book.SaveAs("test.csv", 20) # Unicode テキスト $book.SaveAs("test.csv", 42) $book.Close($false) } catch { Write-Error 'エラーが発生しました' } finally { $excel.Quit() $excel = $null [GC]::Collect() } } else { Write-Error 'ファイルが見つかりません' }
CellsかCells.itemどちらが正しいのかわからない