0

I have a question, my colleague is creating product catalog in our company (in Indesign)

He is updating a version from last year, because we have not much new products BUT all the prices (~7000) are new.

I have never worked with Indesign before, so my question is, is it somehow possible to update OLD prices to NEW prices using ID of products, and the price is always located in the cell next to ID? Please check screenshots.

indesign

This is the table with new Prices, in csv file.

indesign

THANKS for any help.

Nikol

nicusska
  • 177
  • 1
  • 2
  • 9
  • Can't see your screenshots. The short answer is no. It is doable, but there is no easy way. Depends on you import you might be able to reimport or script the update. – Nicolai Kant Aug 11 '17 at 13:24
  • Hello, sorry my fault, I updated images, please check one more time. I appreciate it. Nikol – nicusska Aug 11 '17 at 13:41

1 Answers1

3

Possible workaround is:

  1. read CSV line by line and store current ID and current price
  2. use current ID for doc.findText() method
  3. the parent of 1st found element should be an IDcell
  4. odlPriceCell should be a current table's cell with index +1
  5. use current price for new odlPriceCell contents

sample code:

var
mDoc = app.activeDocument,
mSource = File("~/Desktop/prices.csv"),
// mTarget = mDoc.stories.everyItem().tables.everyItem(),
cLine, cID, cPrice,
cFound, oldID_Cell, target_Cell,
separator = ",";
app.findTextPreferences = null;

mSource.open("r");
do {
cLine = mSource.readln().split(separator);
cID = cLine[0];
cPrice = cLine[1];
if (!cID.match(/^\d+-\d+/)) continue;
app.findTextPreferences.findWhat = cID;
cFound = mDoc.findText();
if (!cFound.length) continue;
oldID_Cell = cFound[0].texts[0].parent;
if (oldID_Cell.constructor.name !="Cell") continue;
target_Cell = oldID_Cell.parent.cells.item(oldID_Cell.index + 1);
target_Cell.texts[0].contents = cPrice;
} while (!mSource.eof);
mSource.close();

Notice mSource path to modify

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
Cashmirek
  • 269
  • 1
  • 9
  • Thank you very much @Cashmirek – nicusska Aug 14 '17 at 06:41
  • Can i have one more question? Is it possible to mark with another color or rewrite value which was not updated by CSV? e.g. with "XXXX" - just to check if there are prices not updated by csv. Nikol – nicusska Aug 14 '17 at 12:02
  • Easier way would be to mark modified cells since script is iterating through entire CSV file but possibly part of INDD prices only. – Cashmirek Aug 14 '17 at 20:53
  • I suggest to create a new color (tint?) and add the line: targetCell.fillColor = newColor ==> before end of do...while loop It will be easy to remove it when no needed - just delete a color – Cashmirek Aug 14 '17 at 20:56