Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # We have to find the start of each section.
- # "Question Sequence" is always in column B underneath the actual title
- # hence we subtract 1 for the actual start row.
- $SearchTerm = "Question Sequence"
- $Headings = @()
- $Range = $ws.UsedRange()
- $Match = $Range.Find($SearchTerm)
- $First = $Match
- Do
- {
- $Row = $Match.Row - 1
- $Headings += $Row
- $Match = $Range.FindNext($Match)
- } while ($Match -ne $NULL -and $Match.AddressLocal() -ne $First.AddressLocal())
- Write-Host " Client: " $Report.ClientName
- Write-Host " Counselor: " $Report.Counselor
- # Now that we know where each heading starts, we'll need to use that data.
- # We'll create Section objects and put them inside of the Report object.
- # We'll create an array to hold the Sections, and then add it as a member when we're finished.
- $Sections = @()
- # Here is where we create the Section objects.
- $count = $Headings.Count
- for ($i=0, $i -le $count, $i++)
- {
- $Section = New-Object -Type System.Object
- $Section | Add-Member -Type NoteProperty -Name Name -Value $ws.Range("B" + $Headings[$i]).Text
- # We have to find where our current section ends.
- # Easiest way to do that is to find the next one and subtract one.
- # If this is the last section, use the last cell of the worksheet.
- if ($i -eq $Headings.Count)
- {
- $end = $ws.UsedRange().Row
- }
- else
- {
- $end = $Headings[$i + 1] - 1
- }
- $Sections += $Section
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement