Laptop Issue Letter(Excel에서 지정한 내용을 읽고 새 Excel 파일을 생성)
9097 단어 Excel
$xl = New-Object -ComObject "Excel.Application"
$cmdbwb = $xl.Workbooks.Open("F:\Ivan\HZCMDB.xlsx")
$cmdbws = $cmdbwb.Worksheets.Item("02--Laptop")
$row = Read-Host -Prompt " Excel "
$details = [pscustomobject][ordered]@{
EmployeeNo = $cmdbws.range("A$row").text
EmployeeName = $cmdbws.range("B$row").text
SeatNo = $cmdbws.range("C$row").text
Project = $cmdbws.range("D$row").text
Model = $cmdbws.range("E$row").text
ServiceTag = $cmdbws.range("F$row").text
FinanceNo = $cmdbws.range("G$row").text
RAM = $cmdbws.range("H$row").text
Hostname = $cmdbws.range("I$row").text
}
$letterwb = $xl.Workbooks.Open("F:\Laptop Issue letter\template.xlsx")
$letterws = $letterwb.Worksheets.Item("sheet1")
$letterws.Range("B1").Value2 = (Get-Date -Format yyyy-M-dd) #
$letterws.Range("B2").value2 = $details.EmployeeName #
$letterws.Range("D9").value2 = $details.Model.Split(" ")[0] #
$letterws.Range("F9").value2 = $details.ServiceTag #
$letterws.Range("H9").value2 = $details.FinanceNo #
$letterwb.SaveAs("F:\Laptop Issue letter\Laptop Issue_" + $details.EmployeeName + " (" + (Get-Date -Format yyyy-M-dd) + ").xlsx")
$xl.Quit()
$letterws = $null
$letterwb = $null
$cmdbws = $null
$cmdbwb = $null
$xl = $null
[GC]::Collect()
#[System.Runtime.InteropServices.Marshal]::ReleaseComObject($xl)
#Remove-Variable xl
$mail = New-Item -Path 'F:\Laptop Issue letter\mail.txt' -ItemType file -Force
$firstline = 'Dear ' + $details.EmployeeName + ','
$secondline = 'You are hereby being issued a Laptop having the Service tag ' + $details.ServiceTag + ' and Finance asset no ' + $details.FinanceNo + ' for official purpose.'
$thirdline = 'Pls print following attachment 3 copies and sign then submit to IS and Admin for tracking, one copy is kept by yourself. Admin will inform security guard to allow you take the laptop in and out office.'
Add-Content -Path $mail -Value $firstline
[Environment]::NewLine | Out-File $mail -Encoding ascii -Append
Add-Content -Path $mail -Value $secondline
[Environment]::NewLine | Out-File $mail -Encoding ascii -Append
Add-Content -Path $mail -Value $thirdline
[Environment]::NewLine | Out-File $mail -Encoding ascii -Append
Add-Content -Path $mail -Value 'yours,'
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Excel Grep toolExcel Grep tool ■히나가타 ■ 시트 구성 ExcelGrep.cls...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.