Jump to content

Export CSV with windows file endings (CRLF)


shunk

This topic is 7159 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • 1 month later...

several weeks later and I'm still no closer to finding a solution. Just for some further info, I'm working on Mac OS X and trying to get it to export as a csv file with CRLF line endings.

At the moment I'm having to export a file out as a csv, take it into a code editor, change the line endings and then resave the file. I'm then emailling the file to someone who i beleive is importing the exported file into an access database.

If anyone can think of a better way of doing this, I'd appreciate your advice!

Link to comment
Share on other sites

This will do it with AppleScript. It can also be done with an XSL stylesheet.

I don't know exactly what output you want for the Vertical Tabs (if any). The following will convert them into period space ". "

[Much of the code is to make sure that AppleScript's text item delimiters don't get left set to other than their default, which is "".]

gText.csv is on the Desktop. Copy/paste below into Script Editor and/or into FileMaker Perform AppleScript step:

set outputFile to (((path to desktop) as text) & "gText.csv") as file specification

global newtext

tell application "Finder" -- needed inside FileMaker

set theText to read outputFile

set myText to my replaceEnding(theText)

set finalText to my replaceVT(myText)

open for access outputFile with write permission

try

set eof of outputFile to 0

write finalText to outputFile starting at eof

close access outputFile

on error errMsg number errNum

try

close access outputFile

end try

set returnString to errMsg & return & "Error Number: " & errNum

display dialog returnString giving up after 10

end try

end tell

on replaceEnding(someText)

try

set AppleScript's text item delimiters to {ASCII character 13}

set textList to text items of someText

set AppleScript's text item delimiters to {(ASCII character 13) & (ASCII character 10)}

set newtext to (textList as text)

on error errMess number errNum

set AppleScript's text item delimiters to ""

set newtext to someText

end try

set AppleScript's text item delimiters to ""

return newtext

end replaceEnding

on replaceVT(someText)

try

set AppleScript's text item delimiters to {ASCII character 11}

set textList to text items of someText

set AppleScript's text item delimiters to {". "}

-- change the Vertical Tab to period space

set newtext to (textList as text)

on error errMess number errNum

set AppleScript's text item delimiters to ""

set newtext to someText

end try

set AppleScript's text item delimiters to ""

return newtext

end replaceVT

Link to comment
Share on other sites

This topic is 7159 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.