Google Apps脚本网格列文字与中心对齐

时间:2014-10-29 13:13:11

标签: css google-apps-script google-sites

grid.setWidth('600px')
  .setBorderWidth(0)
  .setCellPadding(10)
  .setCellSpacing(0)
  .setWidget(0, 0, app.createLabel(''))
  .setWidget(0, 1, app.createLabel('Not Qualified'))
  .setWidget(0, 2, app.createLabel('Directed'))
  .setWidget(0, 3, app.createLabel('Skilled'))

  .setWidget(1, 0, app.createLabel('Manager'))
  .setWidget(1, 1, pmRadio1) // Radio Button
  .setWidget(1, 2, pmRadio2) // Radio Button
  .setWidget(1, 3, pmRadio3) // Radio Button

  .setColumnStyleAttribute(1, "text-align", "center")

我想将单选按钮居中对齐标题标签" Manager"。我在text-align中将center作为setColumnStyleAttribute。但它不起作用。

也尝试了下面的代码。不工作

  var tt = {'text-align': 'center'}
  grid.setColumnStyleAttributes(1, tt)

第一列应该左对齐& Sencond列应居中对齐。

1 个答案:

答案 0 :(得分:1)

请参阅documentation for setColumnStyleAttribute() method:属性名称必须位于 camelCase 中,因此请使用'textAlign'代替'text-align'

<强>更新

由于您使用标签小部件填充网格单元格,因此必须使用.setStyleAttribute('textAlign', 'center')将样式应用于单个标签,或使用网格.setStyleAttributes(row, column, {attributes})方法将样式应用于包含标签/小部件的单元格。

您尝试使用的.setColumnStyleAttribute(column, attribute, value)方法在网格表中创建<colgroup>元素,并将样式应用于colgroup中指定的<col>元素。但是,most of style attributes are not supported in <col> element in HTML5,包括text-align属性 - 这就是为什么您认为使用此方法无效的原因。

相关问题