I have a function to open a Excel sheet and one to manipulat differend cells in a excel sheet. Now I'd like to save and close the the Excel-data.
But I pass only the Sheet object. How can I jump "back" to the workbook and the apllication object?
My Code:
function OpenExcelTablle{
param(
[Parameter(Position=1,mandatory=$true)]
[string] $pwdPath,
[Parameter(Position=0,mandatory=$true)]
[string] $file
)
#Program definieren
$excel = New-Object -ComObject Excel.Application
#password auslesen
#Passwort für Exceldatei einlesen
$password = get-content -Path $pwdPath
#im hintergrund ausführen
$excel.visible = $false
#Datei öffnen
$workbook = $excel.workbooks.open($file,3,0,5,$password,$password)
$blatt= [int](Get-Date -Format "MM")+2
return $workbook.Worksheets.Item($blatt)
}
function DatenSchreiben{
param(
[Parameter(Position=1,mandatory=$true)]
[pscustomobject] $data,#vom Typ CreateAZNObj
[Parameter(Position=0,mandatory=$true)]
[__ComObject] $excelTab
)
$data.ZeilNum = [int](Get-Date -Format "dd")+5
$excelTab.Cells.Item($data.ZeilNum,$data.spNum) = $data.Eintrag
}
function ExExit{
param(
[Parameter(Position=0,mandatory=$true)]
[__ComObject] $excelTab
)
$workbook.save()
$workbook.close()
$excel.Quit()
}
The last function I don't know how to realize. Thanks for support.