Using an Excel file (xlsx) after uploading

Hello,

I’m a bit stuck, I don’t know how to process an Excel file (xlsx) uploaded in PowerShell Universal.

I’m using the following parameters:

powershellCopy code

param(
    
    [Parameter(Mandatory)]
    [ComponentModel.DisplayName("Excel file")]
    [File]$File
) 

[OfficeOpenXml.ExcelPackage] $inputExcel = Open-ExcelPackage $File

I also tried, but since it’s not a CSV or text file, it doesn’t work.

powershellCopy code

[Text.Encoding]::UTF8.GetString($File.Content)

This piece of code is not working.

Can you help me?

Product: PowerShell Universal
Version: 4.2.12

‘it does not work’ is not something we can troubleshoot.

Hello JQ1983.
I don’t understand your message, how will it help me? We’re on a forum. I’m asking for help. No need to be nasty. If I’ve posted a message, it’s because I haven’t found a solution.

Hello

Can anyone help me please?

Thank you very much

Please be more eleborate in your problem description. Your code snippets by themself do nothing. What is working and what isn’t working. What (error) messages do you get. Post a peace of sample code. Etc.

I’ll try to explain my problem clearly.
I want to process an Excel file in a job (i.e. a manual operation) with the [File] parameter in my script.

param(
    [Parameter(Mandatory)]
    [ComponentModel.DisplayName("Excel file")]
    [File]$File
) 

So I need the path to my file so that I can process it via an Excel module.

[OfficeOpenXml.ExcelPackage] $inputExcel = Open-ExcelPackage $pathtomyfile

I can’t find the option to get the path to my file.

I hope I’ve made my problem a little clearer.

Thanks in advance for your help

Are you using a runas account and what environment are you using. There apears to be a bug when using a runas account, the uploaded file can’t be found then.
If I us the integrated environment with default credentials, the file is uploaded and the content is available in the $page variable with this code:
param( [Parameter(Mandatory)] [ComponentModel.DisplayName("Excel file")] [File]$File ) [Text.Encoding]::UTF8.GetString($File.Content)

Thanks for your help

I’ve already tried this option but it doesn’t work because it’s not a “text” file.

I have the impression that this option tries to read the contents of the file. In my case, I don’t need to read the contents, but I do need to have the file path so that I can process it with an Excel module for Powershell.

I guess if you want it to be a file, you have to write $File to a file and then open it.