今回は前回の改良版とも言えるスクリプトです。今回は行単位で色を変えるだけでなく、タブで区切られた文字ごとに四角形を描いて、そこに文字を配置します。単純に言えばエクセルで作ったデータを表組にしますよ、ということです。やり方はエクセルで表をコピーしテキストファイルとして保存します。あとは配置したいドキュメントを作成するか開いてからスクリプトを実行します。
			色の変更方法は前回と同様です。セルの横幅は
		stepX = 100;   // 100pt、横の間隔
 
		の100の数値を変えてください。単位はポイントになっています。文字数に応じて自動的に調整することも一応可能です。縦幅は
		の15の数値を変えます。若干文字の横位置を調整したい場合には
		newText(aWord[i], tx+i*stepX+3, ty);
 
		の+3の値を変えます。縦の位置を調整する場合にはtyをty+2のように変えてください。
		
			【スクリプト】
			TAB = String.fromCharCode(9);
			colorList = [
			     defColor(100,0,0,0),
			     defColor(100,20,0,0),
			     defColor(50,0,50,0),
			     defColor(10,0,100,0)
			];
			filename = File.openDialog("読み込むテキストファイルを指定してください");
			if (filename)
			{
			     tx = 10;  // 表示開始X座標
			     ty = 800; // 表示開始Y座標
			     stepX = 100;   // 100pt、横の間隔
			     stepY = 15;    // 15pt;
			     fileObj = new File(filename);
			     flag = fileObj.open("r");
			     if (flag == true)
			     {
			          count = 0;
			          while(!fileObj.eof)
			          {
			               text = fileObj.readln();
			               n = count % colorList.length;
			               aWord = text.split(TAB);
			               for (i=0; i<aWord.length; i++)
			               {
			                    drawRect(tx+i*stepX, ty, stepX, 15, colorList[n]);
			                    newText(aWord[i], tx+i*stepX+3, ty);
			               }
			               count++;
			               ty -= stepY;
			          }
			          fileObj.close();
			     }else{
			          alert("ファイルが開けませんでした");
			     }
			}
			function newText(txt, x, y)
			{
			     var textObj = activeDocument.textFrames.add();
			     textObj.contents = txt;
			     if (txt) textObj.paragraphs[0].size = 9; // 9pt
			     textObj.translate(x,y);
			}
			function drawRect(x,y,w,h, col)
			{
			     var pObj = activeDocument.pathItems.rectangle(y+h-3,x,w,h);
			     pObj.filled = false;     // 塗りなし
			     pObj.stroked = true;     // 線あり
			     pObj.strokeWidth = 0.25; // 線幅0.25ポイント
			     pObj.fillColor = col;    // 塗りの色をスォッチに指定
			}
			function defColor(c,m,y,k)
			{
			     var colObj = new CMYKColor();
			     colObj.cyan = c;
			     colObj.magenta = m;
			     colObj.yellow = y;
			     colObj.black = k;
			     return colObj;
			}
		
			
			[
サンプルをダウンロード]