import to excel

Hey Hey People,

Im a bit lost on how to create this, but i need a “simple” script to import a textfile which is seperated by commas

got alot of files ( one liners ) that i need imported to excel, but i need it to import in tables, so if one file has this

item1,item2,item3,item4,item5 the script creates 5 rows each showing one item…

can somebody help me on this ?

(sorry the bad english)

This script will work to read a text file and create an Excel table with all the items that are separated by commas in their own row, first column:

set a to choose file --Select your .txt file you want processed
set aa to open for access a
set b to read aa --This will read everything in the chosen file
close access aa
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set c to b's every text item --This creates a list of all the text that is separated by commas
set AppleScript's text item delimiters to astid

tell application "Microsoft Excel"
	activate
	repeat with cc from 1 to (c's length)
		set value of cell 1 of row cc to (item cc of c) --This will create a new row for each item, and place that item in the first cell
	end repeat
end tell

Try it out on a few files to make sure it works, then we can help you to get it to process as many files as you need, creating separate worksheets for each.

thx alot, but im getting this error?

Microsoft Excel got an error: Can’t set value of cell 1 of row 1 to “0710120610”.

this i my first line

“CMM”,0710120610,0710120001,86409496,4767244835,0000000002610820074,3815.34,2007,1008,20071009

I used your data and it worked fine for me. Did you make any changes to the script? What version of OS X are you running?

aha, my bad, Excel was not open in a new worksheat, and yes it is working, but only in one row.

im testing with

“CMM”,0710120610,0710120001,86409496,4767244835,0000000002610820074,3815.34,2007,1008,20071009
“CMM”,0710120610,0710120001,86409496,4767244835,0000000003310920073,580.80,20071,010,20071011

i this case i would need 9 rows…

Hi,

this could be easier

tell application "Microsoft Excel" to open text file filename ((choose file) as Unicode text) with comma