Skip to main content
September 4, 2017
Question

Data Merge - TEXT .txt

  • September 4, 2017
  • 2 replies
  • 1126 views

Hello,

I'm new in scripts.

I hope that sombody has already solved my problem.

I would merge several .txt files in my document InDesign with the "Data Merge" option.

I have a complex csv file (also with several linked images) and I would write .txt links as @images in my sheet.

Do you think it's possible?

How can I do?

Thank you!!

Elisa

This topic has been closed for replies.

2 replies

September 4, 2017

Thank you!

You can download an example here.

https://we.tl/V84OfKosSn

You should change all links in the csv file.

Macintosh HD:Users:iMac01_Grafica:Desktop:esempio csv:txt:2.txt

Macintosh HD:Users:iMac01_Grafica:Desktop:esempio csv:jpg:3.jpg

Thank you again

Elisa

Loic.Aigon
Legend
September 5, 2017

I understand better now what you are dealing with and what you want to achieve.

Datamerge indeed won't let you link text files. You can do with images but not text files. So your alternatives at this point are variable :

1) You can think of a macro in Excel that will pickup the text file, read content and replace url by content.

Problem you may have is with carriage returns that may not be properly understood by InDesign datamerge engine.

2) Process datamerge and use script to find urls and replace them by text contents

This one ain't too complex

var main = function() {

var doc = app.properties.activeDocument,

fgp = app.findGrepPreferences.properties,

findProps = {

findWhat : "^Macintosh HD.+\\.txt$"

},

found = [],

n = 0,

file,

text,

st,

ip,

errors = [];

if ( !doc ) return;

app.findGrepPreferences = null;

app.findGrepPreferences.properties = findProps;

found = doc.findGrep();

n = found.length;

while ( n-- ) {

text = found;

st = text.parentStory;

ip = st.insertionPoints[text.index];

file = File ( text.contents );

if ( file.exists ) {

text.contents = "";

ip.place ( file );

}

else {

errors.push ( "Couldn't find file : "+text.contents );

}

}

app.findGrepPreferences.properties = fgp;

alert( errors.length ? "Errors happen:\r"+errors.join("\r") : "All went fine" );

}

var u;

app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

3) Or you may want to turn your csv into XML for later XML Import within InDesign

So the script will parse the CSV file and append text strings from the text files.

Quite easy too but it's better to have some xml import inside InDesign knowledge.

Loic.Aigon
Legend
September 4, 2017

Maybe…A glance at your source and document may help us