سؤال

I'm using this library to convert a block to a CSV. However, when it encounters a string with a comma in it it molds that string. Normally not a problem except that the curly-braces seem to confuse Excel.

So, {This, is a test} gets turned into | {this | is a test} | (each side of the comma is put into separate cells).

At first I thought I needed to escape the comma but it turns out what I need to do is turn the curly braces into quotes. Is there a quick or REBOL-recommended way to do this?

هل كانت مفيدة؟

المحلول

The purpose of 'MOLD in %csv.r is to wrap values containing commas into double quotes.

But unfortunately 'MOLD puts strings longer than 50 characters into curly braces instead of double quotes, for better readability.

I don't know how to affect this behaviour, so I would just replace 'MOLD in Item: mold Item and Heading: mold Heading with 'DBL-QUOTE, which would simply be defined as

dbl-quote: func[s][rejoin [{"} s {"}]]

نصائح أخرى

Use csv-tools.r instead. It has that functionality built in, and is verified to be Excel compatible. It will work with Rebol 2 and 3, and has been in production use for years.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top