Олег, я надеюсь что ты не назовешь это плагиатом или воровством, но я всетаки "повзаимствовав" сорс скрипта "Ultra Border Maker" решился покаяться и задать очередной вопрос!
Как покрасить ячейку?
with (myTable.cells[0]){
fillColor = "Black" <----?????? Не работает
}
В скрипте все завязано на переменных, а мне хотелось бы указать конкретный цвет ячейки.
В мануале написано:
swatch object or swatch name as string - вроде так и сделал, но не работает!
А делаю вот что:
Скрипт для размещения текста (объявлений в данной случае) с выполнением необходимых замен и рисованием рамок вокруг обзацев определенного стиля.
Дабы меня не обвинили в воровстве сорс прилагается:
//создать документ
var myDocument = app.documents.add(app.documentPresets.item("www"))
//определяем текстовый файл
var myFile = new File("/c/project/test.txt");
with(myDocument){
var myPage1 = myDocument.pages.item(0);
with(myPage1){
//добавляем текстовый фрейм на страницу
var myTextFrame = textFrames.add();
//размеры текстового фрейма
myTextFrame.geometricBounds = [ "10mm", "10mm", "287mm", "103mm"];
//помещаем файл
myTextFrame.place (myFile, autoflowing = true);
//создаем следующий фрейм
myNextTextFrame1 = myTextFrame.nextTextFrame = textFrames.add();
with (myNextTextFrame1){
myNextTextFrame1.geometricBounds = [ "10mm", "107mm", "287mm", "200mm"];
}
}
//добавляем страницу 2
myNextPage = pages.add()
with (myNextPage){
//"продлеваем" текстовый фрейм на стр. 2
myNextTextFrame2 = myNextTextFrame1.nextTextFrame = textFrames.add();
myNextTextFrame2.geometricBounds = [ "10mm", "10mm", "287mm", "103mm"];
myNextTextFrame3 = myNextTextFrame2.nextTextFrame = textFrames.add();
myNextTextFrame3.geometricBounds = [ "10mm", "107mm", "287mm", "200mm"];
}
}
//поиск-замена!!!
with(myDocument){
search ("..",false,false,".");
search ("..",false,false,".");
search ("^p^p",false,false,"^p");
}
//------------------------------ Фаза 2: Рисуем рамки-----------------------------------
var mySwatches = myDocument.swatches;
mySelectedFillColor = "[Black]";
var myStory = myDocument.selection[0].parentStory;
var myParagraphs = myStory.paragraphs
//Определяем стили!!!
var myNormalStyle = "NormalObj";
var myBoldStyle = "BoldObj";
var myRamkaStyle = "Ramka";
var myRamkaBoldStyle = "RamkaBold";
var myBRamkaStyle = "BlackRamNormal";
var myBRamkaBoldStyle = "BlackRamBold";
//----------------------------Поиск обзаца определенного стиля--------------------------
//Find paragraphs with user custom style
for (var myCounter = 0; myCounter < myParagraphs.length; myCounter++) {
if (myParagraphs[myCounter].appliedParagraphStyle.name == myRamkaStyle) {
//Set find paragraphs as current
var myCurrentParagraph = myParagraphs[myCounter]
//if tables in paragraph more at once, ignore this paragraph
if (myCurrentParagraph.tables.length > 1) {
continue;
}
if (myCurrentParagraph.tables.length == 1) {
// If paragraph previous to converted to table
var myTable = myCurrentParagraph.tables[0];
with (myTable) {
width += topBorderStrokeWeight;
}
} else {
var myStartSelection = myCurrentParagraph.characters[0].index;
var myEndSelection = myCurrentParagraph.characters[myCurrentParagraph.characters.length-2].index;
//Set interval of the text to convert to tables
var mySelectedText = myStory.characters.itemByRange(myStartSelection, myEndSelection);
//No need to select text! Just use method! Greate!!!
var myTable = mySelectedText.convertToTable();
}
with (myTable) {
//Apply setting to table
spaceBefore = 1 + " mm";
spaceAfter = 1 + " mm";
//Apply setting to cell
with (myTable.cells[0]){
topInset = 1 + " mm";
bottomInset = 1 + " mm";
leftInset = 1 + " mm";
rightInset = 1 + " mm";
}
}
}
}
//-----------------------Поиск обзаца определенного стиля myRamkaBoldStyle-------------------
//Find paragraphs with user custom style
for (var myCounter = 0; myCounter < myParagraphs.length; myCounter++) {
if (myParagraphs[myCounter].appliedParagraphStyle.name == myRamkaBoldStyle) {
//Set find paragraphs as current
var myCurrentParagraph = myParagraphs[myCounter]
//if tables in paragraph more at once, ignore this paragraph
if (myCurrentParagraph.tables.length > 1) {
continue;
}
if (myCurrentParagraph.tables.length == 1) {
// If paragraph previous to converted to table
var myTable = myCurrentParagraph.tables[0];
with (myTable) {
width += topBorderStrokeWeight;
}
} else {
var myStartSelection = myCurrentParagraph.characters[0].index;
var myEndSelection = myCurrentParagraph.characters[myCurrentParagraph.characters.length-2].index;
//Set interval of the text to convert to tables
var mySelectedText = myStory.characters.itemByRange(myStartSelection, myEndSelection);
//No need to select text! Just use method! Greate!!!
var myTable = mySelectedText.convertToTable();
}
with (myTable) {
//Apply setting to table
spaceBefore = 1 + " mm";
spaceAfter = 1 + " mm";
//Apply setting to cell
with (myTable.cells[0]){
topInset = 1 + " mm";
bottomInset = 1 + " mm";
leftInset = 1 + " mm";
rightInset = 1 + " mm";
}
}
}
}
//-----------------------Поиск обзаца определенного стиля myBRamkaStyle-------------------
//Find paragraphs with user custom style
for (var myCounter = 0; myCounter < myParagraphs.length; myCounter++) {
if (myParagraphs[myCounter].appliedParagraphStyle.name == myBRamkaStyle) {
//Set find paragraphs as current
var myCurrentParagraph = myParagraphs[myCounter]
//if tables in paragraph more at once, ignore this paragraph
if (myCurrentParagraph.tables.length > 1) {
continue;
}
if (myCurrentParagraph.tables.length == 1) {
// If paragraph previous to converted to table
var myTable = myCurrentParagraph.tables[0];
with (myTable) {
width += topBorderStrokeWeight;
}
} else {
var myStartSelection = myCurrentParagraph.characters[0].index;
var myEndSelection = myCurrentParagraph.characters[myCurrentParagraph.characters.length-2].index;
//Set interval of the text to convert to tables
var mySelectedText = myStory.characters.itemByRange(myStartSelection, myEndSelection);
//No need to select text! Just use method! Greate!!!
var myTable = mySelectedText.convertToTable();
}
with (myTable) {
//Apply setting to table
spaceBefore = 1 + " mm";
spaceAfter = 1 + " mm";
//Apply setting to cell
with (myTable.cells[0]){
topInset = 1 + " mm";
bottomInset = 1 + " mm";
leftInset = 1 + " mm";
rightInset = 1 + " mm";
}
}
}
}
//-----------------------Поиск обзаца определенного стиля myBRamkaBoldStyle-------------------
//Find paragraphs with user custom style
for (var myCounter = 0; myCounter < myParagraphs.length; myCounter++) {
if (myParagraphs[myCounter].appliedParagraphStyle.name == myBRamkaBoldStyle) {
//Set find paragraphs as current
var myCurrentParagraph = myParagraphs[myCounter]
//if tables in paragraph more at once, ignore this paragraph
if (myCurrentParagraph.tables.length > 1) {
continue;
}
if (myCurrentParagraph.tables.length == 1) {
// If paragraph previous to converted to table
var myTable = myCurrentParagraph.tables[0];
with (myTable) {
width += topBorderStrokeWeight;
}
} else {
var myStartSelection = myCurrentParagraph.characters[0].index;
var myEndSelection = myCurrentParagraph.characters[myCurrentParagraph.characters.length-2].index;
//Set interval of the text to convert to tables
var mySelectedText = myStory.characters.itemByRange(myStartSelection, myEndSelection);
//No need to select text! Just use method! Greate!!!
var myTable = mySelectedText.convertToTable();
}
with (myTable) {
//Apply setting to table
spaceBefore = 1 + " mm";
spaceAfter = 1 + " mm";
//Apply setting to cell
with (myTable.cells[0]){
fillColor = "Black1";
topInset = 1 + " mm";
bottomInset = 1 + " mm";
leftInset = 1 + " mm";
rightInset = 1 + " mm";
}
}
}
}
Кривой конечно! Но другого не имеем!
Очень надеюсь на ответ!