Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     # We have to find the start of each section.
  3.     # "Question Sequence" is always in column B underneath the actual title
  4.     # hence we subtract 1 for the actual start row.
  5.     $SearchTerm = "Question Sequence"
  6.     $Headings = @()
  7.     $Range = $ws.UsedRange()
  8.     $Match = $Range.Find($SearchTerm)
  9.     $First = $Match
  10.     Do
  11.     {
  12.         $Row = $Match.Row - 1
  13.         $Headings += $Row
  14.         $Match = $Range.FindNext($Match)
  15.     } while ($Match -ne $NULL -and $Match.AddressLocal() -ne $First.AddressLocal())
  16.    
  17.    
  18.     Write-Host "        Client:    " $Report.ClientName
  19.     Write-Host "        Counselor: " $Report.Counselor
  20.  
  21.     # Now that we know where each heading starts, we'll need to use that data.
  22.     # We'll create Section objects and put them inside of the Report object.
  23.     # We'll create an array to hold the Sections, and then add it as a member when we're finished.
  24.     $Sections = @()
  25.  
  26.     # Here is where we create the Section objects.
  27.     $count = $Headings.Count
  28.     for ($i=0, $i -le $count, $i++)
  29.     {
  30.         $Section = New-Object -Type System.Object
  31.         $Section | Add-Member -Type NoteProperty -Name Name -Value $ws.Range("B" + $Headings[$i]).Text
  32.        
  33.         # We have to find where our current section ends.
  34.         # Easiest way to do that is to find the next one and subtract one.
  35.         # If this is the last section, use the last cell of the worksheet.
  36.         if ($i -eq $Headings.Count)
  37.         {
  38.             $end = $ws.UsedRange().Row
  39.         }
  40.         else
  41.         {
  42.             $end = $Headings[$i + 1] - 1
  43.         }
  44.         $Sections += $Section
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement