Добавьте границу в строку или ячейку таблицы в GDocs с помощью скрипта Apps - PullRequest
0 голосов
/ 30 октября 2018

У меня есть несколько таблиц в GDoc, и я хочу добавить границу во вновь вставленную строку последней таблицы в GDoc. Приведенный ниже код не добавит границу во вновь созданную строку.

function addBordertoLastTable() {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();

    var tables = body.getTables();

    table = tables[tables.length - 1];
    var tr = table.appendTableRow();

    var cellStyle = (table.getRow(0).getAttributes())
    cellStyle[DocumentApp.Attribute.BOLD] = false;
    cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#343434';
    cellStyle[DocumentApp.Attribute.FONT_FAMILY] = 'Arial';
    cellStyle[DocumentApp.Attribute.FONT_SIZE] = '8';
    cellStyle[DocumentApp.Attribute.BORDER_COLOR] = '#c0c0c0';
    cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#00ff00';
    cellStyle[DocumentApp.Attribute.BORDER_WIDTH] = '8';

    tr.setAttributes(cellStyle);
    tr.appendTableCell('My Text').setAttributes(cellStyle);
    tr.appendTableCell('My Text').setAttributes(cellStyle);
    tr.appendTableCell('My Text').setAttributes(cellStyle);
}

1 Ответ

0 голосов
/ 31 октября 2018

Пожалуйста, обратитесь к документации, предоставленной Google: https://developers.google.com/apps-script/reference/document/attribute

BORDER_COLOR    Enum    The border color, for table elements.
BORDER_WIDTH    Enum    The border width in points, for table elements.

BORDER_WIDTH и BORDER_COLOR являются таблицей свойствами, а не свойствами ячейки.

Вы можете добавить следующие строки в конце вашей функции, чтобы она работала:

var tableStyle = {};
tableStyle[DocumentApp.Attribute.BORDER_WIDTH] = 8; 
tableStyle[DocumentApp.Attribute.BORDER_COLOR] = '#c0c0c0';
table.setAttributes(tableStyle);

Если новичок читает это, было бы также неплохо удалить определения BORDER_COLOR и BORDER_WIDTH из cellStyle, чтобы сделать код легче для чтения.

...