2017-08-11 22 views
0

我有一個問題,我的同事是我們公司(在InDesign)Indesign - 當我知道產品的ID時,是否可以更新單元格中的值?

他正在更新,從去年的版本,因爲我們已經沒有太多的新產品,但所有的價格(〜7000)創建產品目錄的新。

我之前從未與Indesign合作過,所以我的問題是,是否有可能使用產品ID將舊價格更新爲新價格,並且價格總是位於ID旁邊的單元格中?請檢查截圖。

indesign

這是新的價格表,在csv文件。

indesign

感謝您的幫助。

NIKOL

+0

無法看到你的截圖。最簡潔的答案是不。這是可行的,但沒有簡單的方法。取決於您的導入,您可能可以重新導入或腳本更新。 –

+0

你好,對不起我的錯,我更新了圖片,請再檢查一次。我很感激。 Nikol – nicusska

回答

2

可能的解決方法是:

  1. 由線讀CSV線和存儲電流ID和當前價格
  2. 使用當前的ID爲doc.findText()方法
  3. 的父第一個找到的元素應該是IDcell
  4. odlPriceCell應該是索引爲+1的當前表格單元格
  5. 使用目前的價格爲新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 = ",", 
test, testParent, testTable; 
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路徑修改

+0

Aaaaa你是英雄!它就像一個魅力:) – nicusska

+0

非常感謝@Cashmirek – nicusska

+0

我可以有更多的問題嗎?是否可以使用另一種顏色標記或重寫未更新爲CSV的值?例如與「XXXX」 - 只是爲了檢查是否有價格沒有更新csv。 Nikol – nicusska

相關問題