Hi Everyone,
I have had a request from some people to change an Excel Spreadsheet text to another formatting type.
For example:
From this format (an Excel file):
Sunday 6/17 Monday 6/18
7:00 AM I Love Jazz SOTA 14
7:30 AM BTM 12 SOTA 15
8:00 AM BTM 13 SOTA 16
to:
2010-06-17 7:00:00 I Love Jazz
2010-06-17 7:30:00 BTM 12
2010-06-17 8:00:00 BTM 13
2010-06-18 7:00:00 SOTA 14
2010-06-18 7:30:00 SOTA 15
2010-06-18 8:00:00 SOTA 16
These files are for a server schedule that is created in Excel (the top one) and I want to create a CSV in the second format to import into the scheduler. Can Applescript manipulate through data this way?
If you just make them change the way the are entering the data like it is in the second one, then you could just
export it as a CSV file, (the spread sheet). I can’t see that this rearrangement of the input data should lead to any practical difficulties, it would maybe be practical to have the day of the week in one column in front of the others.
You would then of course only export the columns with the data you need, and see if it is ok to do it manually, then you have figured out the steps to program it.
Is which is described below what you really want to achieve ?
I tried to display the different steps of the process.
17 juin 2010 18 juin 2010
07:00 I Love Jazz SOTA 14
07:30 BTM 12 SOTA 15
08:00 BTM 13 SOTA 16
17 juin 2010 18 juin 2010
07:00 I Love Jazz SOTA 14
07:30 BTM 12 SOTA 15
08:00 BTM 13 SOTA 16
17 juin 2010 18 juin 2010
07:00 I Love Jazz SOTA 14
07:30 BTM 12 SOTA 15
08:00 BTM 13 SOTA 16
17 juin 2010 18 juin 2010
07:00 I Love Jazz 07:00 SOTA 14
07:30 BTM 12 07:30 SOTA 15
08:00 BTM 13 08:00 SOTA 16
17 juin 2010 18 juin 2010
17 juin 2010 07:00 I Love Jazz 18 juin 2010 07:00 SOTA 14
17 juin 2010 07:30 BTM 12 18 juin 2010 07:30 SOTA 15
17 juin 2010 08:00 BTM 13 18 juin 2010 08:00 SOTA 16
17 juin 2010 07:00 I Love Jazz
17 juin 2010 07:30 BTM 12
17 juin 2010 08:00 BTM 13
18 juin 2010 07:00 SOTA 14
18 juin 2010 07:30 SOTA 15
18 juin 2010 08:00 SOTA 16
I repeat that it would be useful to know what is used as values separator.
May be TAB
may be comma
may be semi-colon
may be chunk of spaces
I apologize but as I’m not a sooth sayer, I can’t guess this kind of thing.
Hi Guys,
Sorry, to clarify, the first part is an excel spreadsheet with the data you see separated into their own respective cell. THis is done because our magazine has to be formatted this way.
Sunday 6/17 Monday 6/18
7:00 AM I Love Jazz SOTA 14
7:30 AM BTM 12 SOTA 15
8:00 AM BTM 13 SOTA 16
However, our playout scheduler takes a txt file in a tab delimited format that is somewhat different.
2010-06-17 7:00:00 I Love Jazz
2010-06-17 7:30:00 BTM 12
2010-06-17 8:00:00 BTM 13
2010-06-18 7:00:00 SOTA 14
2010-06-18 7:30:00 SOTA 15
2010-06-18 8:00:00 SOTA 16
What I want to do is export the Excel data out as a tab delimited txt file and then manipulate the data to match the data of my second example. This way, all I then would have to do is import that file into the playout schedule and avoid having to program the schedule two different ways. What I am not understanding is how to move text around using Applescript and the write it to a file.
I am sorry about the confusion and thank you so much for your suggestions and help.
Confused about this:
assuming the Excel table starts in cell A1, Is “Sunday 6/17” the value in cell A1 or in cell B1?
I’d assume it’s B1, so the dates would be the headers for the columns of server names (if that’s what they are).
I would recommend exporting as comma-delimited vars.
Then use this excellent routine by the late Kai Edwards to convert to a list of lists, which the script can write out to another file in any format you like.
Caveat: it returns an empty field as a double quote.
Its output would look like this:
set excelData to {{"", "Sunday 6/17", "Monday 6/18"}, {"7:00 AM", "I Love Jazz", "SOTA 14"}, {"another row"}, {"etc"}}
The actual field separator is of little consequence: use a script property to declare it.
This makes it easy to switch between different output formats (recycle your scripts :)).
I have yet another solution for you, but I really haven’t the time to implement it for you.
I sense that you really wish to have the date formats as specified. (Not everything in my scheme may work as I haven’t even tested it manually.
a.) Create a new sheet.
b.) Format one column with the date according to your liking.
c.) For each date in the “date row” copy that value three times to the date column.
d.) Duplicate the process for the time values in the column besides the “date column”
e.) Transpose the songs from the row into a column besides the times. That should go.
f.) Export the sheet as CSV
I apologize but, as far as I know, when we read a text file or a CSV one, we aren’t getting a list of lists.
We get a text item or a list of text items (paragraphs) and we must know the delimiter used to build the needed lists.
Here, I assume that the datas are in a chunk of text with three values separated by TAB character in every line.
No, obviously not.
I wasn’t aiming to provide a full recipe…
set csvData to readFile(csvFile) -- open & read CSV file
set csvList to csvToList(csvData) -- convert input to list of lists, using Kai's routine
One point about csv files in general: fields containing commas are enclosed in double quotes.
Some institutions (like my bank) want to be super-safe, and their files will have all fields in double quotes. Kai’s routine can deal with that.
If you are able to edit the handler to get it doing a correct job, I will change my advice but at this time, I repeat that I must know the delimiter to be able to decipher CSV files.
Thanks for pointing that out. I have never used data from Excel, so I was not aware of this.
I suppose I just was lucky to pick a bank which delivers comma-separated data.
I don’t use Excel but for tests, I asked a friend to send to me a ‘CSV’ created on a system using the decimal comma.
Like those created by FileMaker, Bento and Numbers (among numerous ones) they use the semi-colon to reduce the frequency of valus needing to be enclosed between quotes (every decimal numbers in such a case°.
In my own life this is not a problem, I use TSV files but many users are sticked to what I feel as a ridiculous format.