Tinderbox Forum

Another way to export to a spreadsheet

I realise the AppleScript provided by @sumnerg in Basic How-To Q about exporting from TB to spreadsheet Tinderbox Tasks is the best approach.

Nevertheless, I was attempting an easier solution based on previous posts. I would like to finish now both because it will allow me to easily customize the outcome and out of curiosity. It uses Export Selected Note on an agent note, a csv wrapper:

^action($MyString=;$MyString=$ExportAttributes("CSV Export Agent").format(","))^
^value($MyString)^^action($MyString=;)^
^children(/Templates/tCSV Wrapper/tCSV Item)^

and a csv item:

^action($MyString=;$ExportAttributes("CSV Export Agent").each(X){$MyString=MyString+eval("$"+X)})^^value($MyString.replace('""','\\"\\"').replace("\n"," \\\n ").replace("\r"," \\\r "))^^action($MyString=;)^
^children(/Templates/tCSV Wrapper/tCSV Item)^

What I cannot work out is where to instruct for the formatting '","'. Any help much appreciated.

Can you clarify the exact input and output strings needed, or if easier explain the CSV edge case you are trying to avoid.
Enclosing all your value strings in (straight) double-quotes will automatically escape any commas therein.

Where does this $ExportAttributes attribute come from?

Can you post a sample .tbx file?

$ExportAttributes is a custom attribute in which to manually write the names of the attributes that will get exported. It is used in the agent which has this csv export template assigned.

In any case, my primary purpose in this post was to learn how to use the .each() function. I approached it via the csv export cases because I found some examples in the forum.

I can do csv export by writing the attribute fields to be exported in an export template itself, not in an $ExportedAttributes custom attribute. But, about the .each() function, I have read the available documentation and, given my programming skills, I don’t understand how to use it.

I realise the unresolved question in this post may be confusing for future users of the forum wanting to know how to export to csv. Therefore, may I suggest that this post is deleted?

I will explain in a new post the real case I am trying to solve, in need of .each().

Thanks for the explanation. I think we might as well leave your last post here to close out the issue. I assume your new thread is How to remove in export code name and tags appearing in text?