Numbers - split text in rows

Hi.

I’ve made a script here to:

  1. Take a paragraph text in B2, make a list where every sentence is one item (split in the “.”)

  2. Create as many rows as the length of the lists and put each sentence in one row, starting in C2.

  3. Merge the rows in B to make the full paragraph in B2:BX (merged) and each sentence in a separate row in C2:CX.

  4. Then it goes to the next item in B (it was B3 before, but now is BX + 1) and do the same.

Okay, it’s working, no problem, BUT I can keep the period at the end of the sentences because of my “split to list”. Sure, I can add the period when setting the value of each cell, and in the last item, replace the “…” by “.” (because the last item keeps the “.”

Is there a way to split and keep the “.”? Maybe is very basic but after hours here working I think I’m not seeing something.

The full script is below, if you want to see.

Thanks,
Luiz


tell application "Numbers"
	activate
	
	tell table 1 of active sheet of document 1
		set selection range to range "B2" -- select place to start	
		set totalLinhas to row count
		set linhaFinal to 2
		
		repeat row count - 1 times
			
			set colunaInicial to 2
			set linhaInicial to linhaFinal
			
			-- get the text
			-- set theText to cell "B2"'s value as string
			set celulaInicial to "B" & linhaFinal
			set theText to value of cell celulaInicial as string
			set myList to my theSplit(theText, ". ")
			set listSize to count of myList
			
			-- add rows ------- 
			repeat listSize - 1 times
				add row below row linhaInicial
			end repeat
			-------------------------------------------
			
			-- take every item and put in one row
			repeat with a from 1 to (length of myList)
				set linhaAtual to a + linhaFinal
				set theCurrentListItem to item a of myList
				set value of cell (colunaInicial + 1) of row (linhaAtual - 1) to theCurrentListItem
			end repeat
			
			-- merge column B and add row
			set thisRangeName to "B" & linhaInicial & ":" & "B" & (linhaInicial + listSize - 1)
			set the selection range to range thisRangeName
			try -- because if the source has only one sentence, will be just one row and won't merge
				merge range thisRangeName
			end try
			
			-- set range final
			set thisRangeName to "B" & (linhaInicial + listSize)
			try -- because if it will be the last row, it won't work
				set the selection range to range thisRangeName
			end try
			set linhaFinal to (linhaInicial + listSize)
			
		end repeat
		
	end tell
end tell




on theSplit(theString, theDelimiter)
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	try
		set theArray to every text item of theString
		-- restore the old setting
		set AppleScript's text item delimiters to oldDelimiters
		-- return the result
		return theArray
	on error
		return theString
	end try
	
	
end theSplit


Something like here:


set aParagraph to "Take a paragraph text in B2, make a list where every sentence is one item (split in the period). Create as many rows as the length of the lists and put each sentence in one row, starting in C2. Merge the rows in B to make the full paragraph in B2:BX (merged) and each sentence in a separate row in C2:CX."
set theArray to my theSplit(aParagraph, {". ", ".", " ."})

on theSplit(theString, theDelimiter)
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	try
		set theArray to (text items 1 thru -2) of theString
		-- restore the old setting
		set AppleScript's text item delimiters to oldDelimiters
		repeat with anItem in theArray
			set contents of anItem to anItem & ". "
		end repeat
		return theArray
	on error
		return theString
	end try
	
	
end theSplit