Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
12

Match (or find) but replace another column

New Here ,
Jan 15, 2024 Jan 15, 2024

Hi there,

 

I have a catalog, made in Indesing using tables. I need to update prices but I 'd like to make this process automatic because I have thousands of references/codes.

Lets say I have and excel (or csv, txt, etc) with 2 columns, one with Code and the other with the Price €.

Basically, I need a way for Indesing to "match" the code and then update the price in the respective column.   

Martins275519807ogn_0-1705316140384.png

 

Is it possible to use a script for this or does anyone have another solution?

 

Thanks!

TOPICS
How to , Import and export , Scripting
360
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2024 Jan 15, 2024
// get data from the CSV file
var file = File.openDialog("Choose a Remap csv file:");
file.open('r');
var data = file.read().split('\n');
file.close();

// convert the data into the object = {id1:price1, id2:price2, id3:price3, ...}
var obj = {};
for (var i = 0; i < data.length; i++) {
    var row = data[i].split(',');
    var id = row[0];
    var price = row[1];
    if (id != '') obj[id] = price;  // <------------------ here the update
}

// loop through IDs of the object and change cells in the document
var doc = app.activeDocument;
app.findTextPreferences = null;
for (var id in obj) {
    app.findTextPreferences.findWhat = id;
    var founds = doc.findText();
    for (var f = 0; f < founds.length; f++) {
        var cell = founds[f].texts[0].parent;
        if (cell.constructor.name == "Cell")
            cell.parent.cells[cell.index + 6].contents = obj[id];
    }
}
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2024 Jan 15, 2024

.csv format

csv format.png
After:
After.png

 

Before:

Before.png

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 16, 2024 Jan 16, 2024
LATEST

Have you checked this? @Martins275519807ogn 

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines