Indesign - 当我知道产品的 ID 时,是否可以更新单元格中的值?

Indesign - Is it possible to update value in cell when I know ID of the product?

我有一个问题,我的同事正在我们公司(在 Indesign 中)创建产品目录

他正在更新去年的版本,因为我们没有太多新产品,但所有价格(~7000)都是新的。

我以前从未使用过 Indesign,所以我的问题是,是否可以使用产品 ID 将旧价格更新为新价格,并且价格始终位于 ID 旁边的单元格中?请检查屏幕截图。

这是 table 的新价格,在 csv 文件中。

感谢您的帮助。

尼科尔

可能的解决方法是:

  1. 逐行读取 CSV 并存储当前 ID 和当前价格
  2. 将当前 ID 用于 doc.findText() 方法
  3. 第一个找到的元素的父元素应该是 IDcell
  4. odlPriceCell 应该是索引为 +1
  5. 的当前 table 的单元格
  6. 对新的 odlPriceCell 内容使用当前价格

示例代码:

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();

注意修改mSource路径