Powershell - Excel

Hi everybody,
I am trying to find out, whether a specific cell in Excel is filled or not.

I am playing around with a little start-script, which writes the starttime to a specific cell into excel.
What I am struggeling with is to test, whether this cell is already filled.
If the cell is filled, I would like to avoid re-filling it with a new value…
(I cannot find something like “test-path” for excel)

function clock()

{
$Time = Get-Date
$global:Zeit = $Time.tostring("HH:mm:ss")
$global:Zeile = $Time.Day+1
$global:Monat = get-date -format MMMM
}

clock

$objexcel=New-Object -ComObject Excel.Application
$workbook=$objexcel.WorkBooks.Open('H:\Arbeitszeit\2023.xlsx')
$worksheet=$workbook.WorkSheets.item($Monat)
$objexcel.Visible= $false
$worksheet.Cells.Item($Zeile,4)=$Zeit
$workbook.Save()
$objexcel.Quit()

any help would be highly appreciated
newbi

newbi200925,
Willkommen zurück im Forum. :wave:t4: Lange nicht gesehen. :wink:

If it’s an option I’d change to a CSV file instead of native Excel as this would be way easier because this functionality is already builtin in PowerShell.

If it’s not you should take a look at the great module from Doug Finke

With this I’d read the Excel file and simply test the existence of the value the PowerShell way. :wink:

You may learn more about the module from its creator:

oh, I found a solution:

If([string]::IsNullOrEmpty($Worksheet.Cells.Item(x,y).value2)){}

…did the trick!!

Great. And thanks for sharing. :+1:t4: