2017-06-07 5 views
0

Ich habe Code, den ich für ein Google Apps-Skriptmakro verwende. Dies verwendet den DocumentApp TableRow- und den Tabellenzellen-Datentyp.Google Apps Script TableCell akzeptiert keine Attribute

Also wenn ich diese Funktion ausführen, ist die resultierende Zelle in der Zeile immer noch der Standard linksbündig. Fehle ich etwas? Sie haben dieses Beispiel auf ihrer Website.

https://developers.google.com/apps-script/reference/document/table-cell#setAttributes(Object)

var body = DocumentApp.getActiveDocument().getBody(); 

// Define a custom paragraph style. 
var style = {}; 
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = 
DocumentApp.HorizontalAlignment.RIGHT; 
style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; 
style[DocumentApp.Attribute.FONT_SIZE] = 18; 
style[DocumentApp.Attribute.BOLD] = true; 

// Append a plain paragraph. 
var par = body.appendParagraph('A paragraph with custom style.'); 

// Apply the custom style. 
par.setAttributes(style); 

Antwort

0

Mit diesem sample tutorial beziehen. Hier ist ein Beispielcode, der rechtsbündig eine Tabelle mit Zellentext hinzufügt.

function addTableInDocument() { 

    var headerStyle = {}; 
    headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#336600'; 
    headerStyle[DocumentApp.Attribute.BOLD] = true; 
    headerStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#FFFFFF'; 

    //Style for the cells other than header row 
    var cellStyle = {}; 
    cellStyle[DocumentApp.Attribute.BOLD] = false; 
    cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000'; 
    cellStyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; 

    var doc = DocumentApp.getActiveDocument(); 

    //get the body section of document 
    var body = doc.getBody(); 

    //Add a table in document 
    var table = body.appendTable(); 

    //Create 5 rows and 4 columns 
    for(var i=0; i<2; i++){ 
    var tr = table.appendTableRow(); 

    //add 4 cells in each row 
    for(var j=0; j<2; j++){ 
     var td = tr.appendTableCell('Cell '+i+j); 

     //if it is header cell, apply the header style else cellStyle 
     if(i == 0) td.setAttributes(headerStyle); 
     else td.setAttributes(cellStyle); 

     //Apply the para style to each paragraph in cell 
     var paraInCell = td.getChild(0).asParagraph(); 
     paraInCell.setAttributes(cellStyle); 
    } 
    } 

    doc.saveAndClose(); 
} 

enter image description here

Hoffnung, das hilft.

Verwandte Themen