Working with excel

Welcome Forums General PowerShell Q&A Working with excel

Viewing 4 reply threads
  • Author
    Posts
    • #274020
      Participant
      Topics: 3
      Replies: 3
      Points: 42
      Rank: Member

      Hello,

      I am trying to output text from two different variables into two different columns in an excel sheet.

      The two variables are $Default and $custom which contain list of values.

       

      =====================================================

       

      ===========================================================

      Desired output:

      Defaultfiles Customfiles
      oof.json AP.json
      analytics.json OOPS.json
      all-performance.json opp1.json
      memory-2.json opp2.json
      windows-server-2016.json Performance.json
      generic.json Windows Server 2016.json
      memory.json

      Current Output:

      Defaultfiles Customfiles
      oof.json
      analytics.json
      all-performance.json
      memory-2.json
      windows-server-2016.json
      generic.json
      AP.json
      OOPS.json
      opp1.json
      opp2.json
      Performance.json
      Windows Server 2016.json
      memory.json

      Note sure why I get empty cells in the second column. Can anyone help me with tis please.

      • This topic was modified 2 months ago by Afreen90.
    • #274038
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,429
      Helping Hand
      Rank: Community MVP

      The best way to handle excel files in PowerShell is via ImportExcel module. It should server most of the usecases.
      https://www.powershellgallery.com/packages/ImportExcel/7.1.1

    • #274062
      Participant
      Topics: 4
      Replies: 429
      Points: 770
      Helping Hand
      Rank: Major Contributor

      Your problem is that you’re running two separate loops for each of your datasets and both of those loops are adding rows to your table.

      Your second loop either needs to be adding the data to row1, column2 or you need to use a single loop that populates row1: column1, column2; row2: column1, column2 etc.

       

    • #274260
      Participant
      Topics: 3
      Replies: 3
      Points: 42
      Rank: Member

      Hi Matt,

      Thanks for your reply. I have tried using a single loop but could not get desired result. Any example script can hep 🙂

    • #274344
      Participant
      Topics: 4
      Replies: 429
      Points: 770
      Helping Hand
      Rank: Major Contributor

      I stuck with two loops:

       

Viewing 4 reply threads
  • You must be logged in to reply to this topic.