-
-
Save milligramme/792975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
/* | |
* 2011.1.8 InDesign Script勉強会お題① | |
* CSV(二次元配列)の2番目と4番目をフレームに入れる | |
*/ | |
var csv = [ | |
["aaa1","bbb1","ccc1","ddd1"], | |
["aaa2","bbb2\rbbb2","ccc2","ddd2"], | |
["aaa3","bbb3","ccc3","ddd3"], | |
["aaa4","bbb4","ccc4","ddd4"], | |
["aaa5","","ccc5","ddd5"] | |
]; | |
var doc = app.activeDocument; | |
var page = doc.pages[0]; | |
//スタイル分のテキストフレームダミー | |
var pstyleNameArray = ["a1", "a2"]; | |
var ptf = []; | |
for (var i=0, iL=pstyleNameArray.length; i < iL ; i++) { | |
var ptfs = page.textFrames.add(); | |
ptfs.parentStory.appliedParagraphStyle = pstyleNameArray[i]; | |
ptf.push(ptfs); | |
}; | |
for(var i=0, len=csv.length; i<len; i++){ | |
ptf[0].contents = ptf[1].contents = ""; | |
var tf = page.textFrames.add(); | |
tf.geometricBounds=[40*i, 10, 40*i+40, 160]; | |
//各スタイルのテキストフレームに各csv | |
ptf[0].parentStory.contents = csv[i][1]==="" ? "" : csv[i][1]+"\r"; | |
ptf[1].parentStory.contents = csv[i][3]; | |
//textsオブジェクトとして複製 | |
ptf[0].parentStory.duplicate(LocationOptions.AFTER, tf.parentStory); | |
ptf[1].parentStory.duplicate(LocationOptions.AFTER, tf.parentStory); | |
/* | |
* todo:contentsをテキストフレームに入れてからparagraphにスタイルを当てると、改行が入った場合にスタイルがズレる。 | |
* 良い方法はないかな? | |
*/ | |
} | |
ptf[0].remove(); | |
ptf[1].remove(); | |
alert("処理を終わりました。"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment