javascriptgoogle-apps-scriptcolumn-types

Column Attributes Not Applying


I can call setRowStyleAttribute for my flextable which appear correctly (see below). However, when I attempt to call setColumnStyleAttribute, nothing happens.

I also expect Column 0 to be formatted in Bold.

I don't receive any error messages.

function doGet(){
  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();
  var flexTable = app.createFlexTable().setStyleAttribute('border', '1px solid     black')
    .setStyleAttribute('borderCollapse','collapse')
    .setBorderWidth(1); 

  //Add Spreadsheet Key Here
  var spreadsheetId = 'MY KEY';
  var dataArray = getData(spreadsheetId);

  for (var row = 0; row<dataArray.length; row++){
    for (var col = 0; col<dataArray[row].length; col++){
      flexTable.setText(row, col, dataArray[row][col].toString());
    }
  }

  panel.add(
    flexTable.setRowStyleAttribute(1, 'fontWeight', 'bold')
             .setRowStyleAttribute(6, 'fontWeight', 'bold')
             //Set Column 0 to Bold?
             .setColumnStyleAttribute(0, 'fontWeight', 'bold')
  );
  app.add(panel);
  return app;
}




function getData(spreadsheetId){
  var ss = SpreadsheetApp.openById(spreadsheetId);
  //Select Which Sheet and The Range ---> (StartingRow, StartingCol, LengthRow, LengthCol)
  var sheet = ss.getSheetByName('Sheet1').getRange(2,12,7,7);
  return sheet.getValues();
}

Solution

  • EDIT:

    I've played around with this and have found 'font-weight' does not work with setColumnStyleAttribute. All the other attributes I tried seem to work, just not that one.

    And of course UiApp is depreciated. While it seems they are not turning it off, if anything breaks they wont fix it. AND they may turn it off at any time without notice.

    Here is a work around you can set the style in the call as we add the data:

     for (var row = 0; row<dataArray.length; row++){
        for (var col = 0; col<dataArray[row].length; col++){
          flexTable.setText(row, col, dataArray[row][col].toString());
          flexTable.setStyleAttribute(row, 0, 'font-weight', 'bold');
        }
      }
    

    Original post:

    I think with caja the attribute is 'font-weight'. See the caja whitelist for reference. https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/lang/css/css3-whitelist.json