[英]Indesign : in a table cell, how to get and move any paragraph content
I need help for complete my code.我需要帮助来完成我的代码。
I created a table and inserted 4 paragraphs texts and a image into the same cell.我创建了一个表格并将 4 个段落文本和一个图像插入到同一个单元格中。 I want to modify the content of the cell like this:我想像这样修改单元格的内容:
1: move 'text3' before 'text4' 1:将“text3”移动到“text4”之前
2: move the image at the first place 2:首先移动图像
I understood the principe of the insertionpoints, however after many tests i didn't succeed the moves...我了解插入点的原理,但是经过多次测试,我没有成功移动...
Please help me to fix, Thank you !请帮我解决,谢谢!
var myDocument = app.documents.add();
var myPage = myDocument.pages;
var tf = myPage[0].textFrames.add({ geometricBounds: [20, 20, 100, 150] });
insertionpoint = tf.insertionPoints[0];
app.select(insertionpoint);
mySelection=app.selection[0];
mySelection.tables.add({
label : "theTable",
bodyRowCount : 7,
columnCount : 8,
});
tableList = myDocument.stories.everyItem().tables.everyItem().getElements();
myTable = tableList[0];
myTable.columns[4].cells[5].contents = "test2\n";
myTable.columns[4].cells[5].insertionPoints[-1].contents = "test4\n";
myTable.columns[4].cells[5].insertionPoints[0].contents = "test1\n";
myTable.columns[4].cells[5].insertionPoints[-1].contents = "test3\n";
var myFrame = myTable.columns[4].cells[5].insertionPoints[-1].rectangles.add({
name : "theFrame"
});
myFrame.horizontalScale *= 2;
myFrame.verticalScale *= 3;
try
{
myFrame.place(File("Put here a valid local image path"));
}
catch(err)
{
myFrame.fillColor = "Black";
};
myFrame.fit(FitOptions.proportionally);
myFrame.fit(FitOptions.frameToContent);
/* 1: Code for moving "test3\n" paragraph before "test4\n" in the cell (4,5) */
/* 2: Code for moving the rectangle in first place in the cell (4,5) */
Here is the rather clumsy solution but it works:这是一个相当笨拙的解决方案,但它有效:
/* 1: Code for moving "test3\n" paragraph before "test4\n" in the cell (4,5) */
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '^(.+?)\\n(.+?)\\n(.+?)\\n(.+?)\\n';
app.changeGrepPreferences.changeTo = '\\n$1\\n$2\\n$4\\n$3';
myTable.columns[4].cells[5].changeGrep();
/* 2: Code for moving the rectangle in first place in the cell (4,5) */
myFrame.select();
app.cut();
myTable.columns[4].cells[5].insertionPoints[0].select();
app.paste();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.