파워쉘로 엑셀 첫행을 일괄 삭제하려면 어떻게 수정해야 하나요?
#대상 엑셀파일이 존재하는 디렉터리
$destination = "C:\test\"
#대상 엑셀 파일들의 목록을 추출
$dirName = Get-ChildItem -Name -Filter *.xlsm
$saveAs = $destination + "new\"
foreach($z in $dirName){
#엑셀 기동
$excel=New-Object -ComObject Excel.Application
$excel.visible=$false
$excel.DisplayAlerts=$false
#데이터 처리
#엑셀파일 오픈
$book=$excel.Workbooks.Open($destination + $z)
#시트 취득 item(1) 첫번째 시트
$sheet=$book.Worksheets.item(1)
#시트 내용을 수정
$sheet.Cells.Item(1,1)="=now()"
#저장 및 종료처리
$book.SaveAs($saveAs + $z)
$excel.Quit()
$excel=$null
}
#출처 : https://self-interest.tistory.com/32
해당 코드에서 첫 셀에 함수를 넣는 내용의 마지막부분 $sheet.Cells.Item(1,1)="=now()"를 빼고 첫 행을 삭제하는 내용을 넣으려 합니다.
어떤 명령어를 써야 하나요?
55글자 더 채워주세요.
1개의 답변이 있어요!
- #대상 엑셀파일이 존재하는 디렉터리 $destination = "C:\test\" #대상 엑셀 파일들의 목록을 추출 $dirName = Get-ChildItem -Name -Filter *.xlsm $saveAs = $destination + "new\" foreach($z in $dirName){ #엑셀 기동 $excel=New-Object -ComObject Excel.Application $excel.visible=$false $excel.DisplayAlerts=$false #데이터 처리 #엑셀파일 오픈 $book=$excel.Workbooks.Open($destination + $z) #시트 취득 item(1) 첫번째 시트 $sheet=$book.Worksheets.item(1) #시트 내용을 수정 #$sheet.Cells.Item(1,1)="=now()" $sheet.Rows(1).Delete #저장 및 종료처리 $book.SaveAs($saveAs + $z) $excel.Quit() $excel=$null }
을 해보시길 바랍니다.