More direct - no need for select or intermediate variable $s
:
$excelFile = "C:esterTestfile.xlsb"
$Excel = New-Object -ComObject Excel.Application
$wb = $Excel.Workbooks.Open($excelFile)
$wb.worksheets(1).range("C7").showdetail = $true
$wb.saveas("C:esterTestfile_modified.xlsb")
$wb.Close()
$Excel.Quit()
#make sure Excel process is ended (or it may persist)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Remove-Variable Excel
in a script file called from cmd using:
powershell -noexit "& ""C:TesterpsExcelTest.ps1"""
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…