Automatically Create One line from multiple lines of input

I’m afraid I can’t help with Excel. But you could possibly help any potential helpers by clarifying what the output should be and what the input could be. Stefan’s second script, mine, and Shane’s all produce exactly the output you requested in your first post from the input given. In this, the trailing space is removed from "Test7 ", but not from the other lines. This is a bit strange and the other scripts are intelligent attempts to guess at what you may actually have meant. It would help to have some clarity on this point. Also, the ‘word’ solutions will lose any non-alphanumeric characters at the beginning of the first line or at the end of the last, so it would be useful to know if the lines could contain any punctuation or spaces which need to be kept.

Select a single column of your data starting with the first row of data thru the last row of data in Excel. Then, run the following AppleScript:


use framework "Foundation"
use framework "OSAKit"
use scripting additions

tell application "Microsoft Excel"
	activate
	set rowCount to count of rows of selection
	set myString to "" as text
	repeat with j from 1 to rowCount
		set myString to myString & (value of row j of selection) as text
		if j < rowCount then
			set myString to myString & return as text
		end if
	end repeat
end tell

activate
display dialog (((current application's OSAScript's alloc()'s initWithSource:("paragraphs from word 1 to word -1 of \"" & myString & "\""))'s executeAndReturnDisplayValue:(reference) |error|:(missing value))'s end's |string|() as text)

For python there is openpyxl so you can read the spreadsheet file and return the wanted data back to AppleScript without use of spreadsheet software like Microsoft Excel or Numbers.

UPDATE: PM 2017-08-15

This code does as intended, with one small problem when used in the real world with longs strings of text, and more than 45 lines! The text that appears in the output box is so long I can’t copy all of it!

Would it be possible to offer a ‘copy to clipboard’ button, or output the text in another manor that will make copying the final result full proof?

This works perfectly. Thank you.

Thanks for the tip. I am using Microsoft Excel so the script haolesurferdude created works well for me, and saves so much more time.

However, your suggestion is great for anyone not using, or having access to, or even wanting to use Microsoft Excel or Numbers.

Thanks everyone for your input and assistance. :slight_smile:

Can anyone help me with the issue?

The OP showed quite clear input text + quite clear text that he would like to receive as a result. So, here are a bunch of massive solutions, besides this simple one:


set myString to "
Test1 
Test2 
Test3 
Test4 
Test5 
Test6 
Test7 
"

set myList to paragraphs 2 thru -1 of (text 1 thru -3 of myString)