Hi,
I have a folder with a bunch of spreadsheets in it. I want to convert them into .csv files and paste them in the same folder. I found this applescript code (below) which almost does what I want. It takes an open spreadsheet and outputs a .csv file to my Documents folder.
I would like for KM to get the contents of the spreadsheet without having to open it. Is there a way to do this? Perhaps by modifying this applescript?
I looked at that script. It sends commands to Numbers. So I think that means it "opens" Numbers. I don't think it's possible to decode a complex file type in KM without opening the spreadsheet application itself. Are you sure you don't want Numbers to be activated?
Ya, I don't need to open them. It just slows things down. Maybe there are 40 or so different spreadsheets that have to be opened and closed. I need to convert them to .csv so I can work with them as text strings.
In order to read a spreadsheet file you must use an app that can read the file. KM itself cannot read spreadsheet files. But there are programs that can read them, starting with the spreadsheet apps themselves, plus additional utilities that you can obtain or purchase online, plus websites that will convert your files for "free". Each of these choices has advantages and disadvantages. Some cost money, and some cost CPU time. I'm not really sure which option you are most interested in. I would be willing to help you with some of these choices but I'm not sure which one you want.
Some people use Excel-formatted spreadsheet files on macOS. Some use Numbers-formatted files on macOS. Do you know which file type you are using? This will affect the options you have.
In the macro you provided above, the AppleScript send commands to the Numbers program, so I'm guessing you are comfortable with using Numbers to do the work of the conversion, even though you said you wanted to do this work "without opening it [in Numbers]". Is that correct?
Does the new file need to have the same name as the old file? If so, what do you want to happen if there's already a file by the same name in that folder?
That's helpful. I don't really want to invest a lot of money in this project because it is not a routine thing I do. But it would be nice to have a way to convert a spreadsheet.
I actually need to work with both excel and numbers files. But, ya, I typically import the excel files into numbers.
Yes, file name needs to be the same. Just overwrite the old ones.
That applescript I posted sends the output to my Documents folder. Is there an easy way to change that?
As for your question about AppleScript. I'm inept at it. I was able to glance at yours to see what it was doing, but that's about all i can do.
As for KM, scripts are easy. but bear in mind when I write a script for you I won't be modelling it off your AppleScript code because I can't really read that.
Basically here's what I would code:
Let the user pick a folder through a dialog box
For each spreadsheet file in that dialog box do the following
Bring Numbers to the front
Load the spreadsheet into numbers
Send the command to Numbers to export the file to CSV
Press the appropriate OK or OVERWRITE buttons
Close the open file
End Loop
Okay I think I got this pseudo-code working, I'll upload it into the next post. I had to make a couple of changes the the above pseudo code to make it work.
Ok, here's the code. Hmm, I realize I just used .Numbers not .Excel as the source files. If you can't figure out how to get it to add .Excel, let me know.
It seems to work for me. Mind you, I really don't have much experience with this sort of macro so it's possible someone will tell us how to improve this. My solutions are not always the best solutions.
That might be true, but I asked him "I'm guessing you are comfortable with using Numbers to do the work of the conversion, even though you said you wanted to do this work "without opening it [in Numbers]". Is that correct?"
...and he never said no or anything negative, so I inferred that he was comfortable with using Numbers. All he said was "yes."
So if you think he meant to say no, how would you solve this problem?