Скрипт приведен в листинге 8.12.

Листинг 8.12. Форматирование таблицы, импортированной из Word

Obj = {w:{narrow:120, wide:174}, flag:[false,false,false,false], ’b alterFill:"K 8%", headerFill:"K 15%"}; step = 2;

DEF_SIDE_INSET = DEF_STROKE_W = 0.5;

VERT_INSET = 1;

aD = app.activeDocument; sel = aD.selection[0]; tbl = sel.parent.parent; withftbl.cells)

{

cellsTbl = itemByRange(firstltem(), lastltemO);

}

with(tbl.rows)

{

rowsTbl = itemByRange(firstltem() , lastltemO);

}

tF = tbl.parent; pS = aD.paragraphStyles; pars = sel.paragraphs; curr_para = pars[0];

startP = pars.previousItem(curr_para); endP = pars.nextltem(curr_para);

value = prompt("Table width (Narrow/Wide) [1/2]: ", "1") table_W = (value==l) ? Obj.w.narrow : Obj.w.wide; pSA = [];

for (i=2; i<pS.length; i++)

{

switch(pS[i].name)

{

case 'Table Headef:

pSA['Table Header'] = i; Obj.flag[0] = true; break; case 'Table Footer':

pSA['Table Footer'] = i; Obj.flag[l] = true; break; case 'Table contents':

pSA['Table contents'] = i; 0bj.flag[2] = true break;

case 'Table':

pSA['Table'] = i; Obj.flag[3] = true;

break; case 'ТЫ Hdr':

pSA['Tbl Hdr'] = i; Obj.flag[4] = true;

break;

}

}

with(Obj)

if(flag[0] && flag[l] && flag[2] && flag[3] && flag [4])

{

if(sel.constructor.name == "InsertionPoint" || sel.constructor.name - "Paragraph")

{

with(cellsTbl)

{

texts[0].appIyStyle(pS [pSA ['Table contents']], true) verticalJustification = VerticalJustification.centerAlign if (rowSpan=l && lines. length>0)

{

height = 0

}

toplnset = bottomlnset = VERT_INSET + " ram" leftlnset = rightlnset = DEF_SIDE_INSET + " mm"

}

with(tbl)

{

altematingFills = AlternatingFillsTypes.alternatingRows;

startRowFillCount = 1;

startRowFillColor = Obj.alterFill;

endRowFillColor = "None";

startRowFillTint = 100;

skipFirstAlternatingFillRows = 1

width = (columns.length<5 || table_W==Obj.w.narrow) ?

Obj.w.narrow : Obj.w.wide

)

with(rowsTbl)

{

topEdgeStrokeWeight = 0; bottomEdgeStrokeWeight = 0;

cells[0].texts[0].justification = 1818584692

}

for (i=0; i<tbl.rows.length; i++)

{

with(tbl.rows[i].cells[0]) while(lines.length>l && width<50) width += step

}

with(tbl) {

for (i=0; i<columns.length; i++) { with (columns[i]) {

leftEdgeStrokeColor = aD.swatches[1]; rightEdgeStrokeColor = aD. swatches [1] ; leftEdgeStrokeWeight = DEF_STROKE_W + " pt"; rightEdgeStrokeWeight = DEF_STROKE_W + " pt”; if(i>0)

{

width = (table_W-parent. columns [0] . width) /

(parent.columns.length-1)

}

}

}

}

myCellName = mySelection.parent.name myCellRow = myCellName.split(":")[1]

myTable.rows[0].select for(k=l; k< myCellRow; k++)

{

myTable.rows[k].select(SelectionOptions.addTo)

}

with(myDocument.selection[0])

{

rowType = RowTypes.headerRow fillColor = Obj.headerFill

texts[0].applyStyle(pS[pSA['ТЫ Hdr']],true)

}

aD.select(NothingEnum.nothing)

curr_para.applyStyle(pS[pSA['Table']], true); pars.previousItem(curr_para).applyStyle(pS[pSA['Table Header']], true)


⇐ вернуться назад | | далее ⇒