79456339

Date: 2025-02-21 04:17:32
Score: 0.5
Natty:
Report link

It seems to be happening because PowerShell Export-Excel is creating a 'minimal' Excel file, with no version information. And when your EXCEL opens it it makes some assumptions, and thinking that XLOOKUP can potentially return an array, it makes sure that only the first item is returned (by adding the @). I am not sure how to 'inject' a version number (and make content compatible with that format) into the exported file. Since you do this row by row, why not use VLOOKUP?

    $data = Import-Excel -path "C:\SomeWorkbook.xlsx"
$row = 2
$data | ForEach-Object { 
    $_ | Add-Member -MemberType NoteProperty -Name "Role" -Value "=VLOOKUP(E$Row,UserData!A:F,3,FALSE)"
    $_ | Add-Member -MemberType NoteProperty -Name "Department" -Value "=VLOOKUP(E$Row,UserData!A:F,4,FALSE)"
    $_ | Add-Member -MemberType NoteProperty -Name "Division" -Value "=VLOOKUP(E$Row,UserData!A:F,5,FALSE)"
    $_ | Add-Member -MemberType NoteProperty -Name "Manager" -Value "=VLOOKUP(E$Row,UserData!A:F,6,FALSE)"
    $row++
}
$data | Export-Excel -path "C:\SomeWorkbook.xlsx" -worksheetname "Appdata"
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Looks like a comment (1):
  • High reputation (-1):
Posted by: tinazmu