0

Hi :) I'm still struggling with my program and still trying to learn new techniques with PowerShell. Now, I'm going to use Import-Excel and I'm trying to get the KEY and VALUE of File_1.xlsx from the "L6 and M6" Column then compile its value with a comma inside a cell where the Key name is the same.

Just like this sample image here: enter image description here

but first, I want to Know how to get the Columns for L and M and just figure out the rest:

  1. Get all the Input Files (I have multiple Input Files and Worksheets)
  2. Get the Key and Value from L and M Column
  3. Compile all Value with the Same Key names
  4. Convert it to CSV

I'm following the solution by Sir Santiago, but I can't get the L and M Column How to export a specific Excel column with PowerShell?

$Source = "C:\PS"
$Output = 'C:\Out\Output.csv'
$Files = GCI "$Source"

ForEach ($File in $Files) {
$Data = @'
Key, $File.Name
$_Key, $_Value
'@
}

$Data | Export-Excel $Output

Import-Excel $Output -ImportColumns 12, 13 -HeaderName Key, $File.Name -DataOnly

Or am I getting the idea Wrong? Sorry for asking this multiple times, just can't get the right thing to do this.

1 Answer 1

1

It's not entirely clear how you want to save your output. But below is the code to join all values in one file.

$source=import-excel C:\temp\file_1.xlsx -StartRow 5 -StartColumn 11

$keys=$source.keys |select -Unique
$data=@{}
foreach($k in $keys) {
    $vals=($source|where {$_.key -eq $k}).value -join','
    $data.add($k,$vals)
}
Sign up to request clarification or add additional context in comments.

2 Comments

I just want to save/export it as a CSV file
I just mean that it's not entirely clear how it would look in the output-file when several files have been added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.