设置边框颜色 &以编程方式在电子表格中设置样式 [英] Set border color & style in spreadsheet programmatically

查看:8
本文介绍了设置边框颜色 &以编程方式在电子表格中设置样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 电子表格在边框按钮下方的工具栏中还有一个用于更改颜色和更改边框样式的按钮.

Google Spreadsheet has in the toolbar under the border button also a button to change the color and change the border style.

如何在 Google Apps 脚本中访问这些内容?

How can these be accessed within a Google Apps Script?

为文档描述的 setBorderColor 函数似乎不适用于电子表格.

The setBorderColor function which is described for documents seems unavailable for spreadsheets.

推荐答案

报告的问题已修复,截至 2016 年 1 月 12 日.Range 现在有这些方法:

The reported issue has been fixed, as of 12 Jan 2016. Range now has these methods:

  • setBorder(top, left, bottom, right, vertical, horizontal), as before.
  • setBorder(top, left, bottom, right, vertical, horizontal, color, style), NEW!

文档中提供了示例;以下是设置红色虚线边框的方法*:

Examples are provided in the documentation; here's how to set a dashed red border*:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var cell = sheet.getRange("B2");
// Sets borders on the top and bottom, but leaves the left and right unchanged
// Also sets the color to "red", and the border to "DASHED".
cell.setBorder(true, null, true, null, false, false, "red", SpreadsheetApp.BorderStyle.DASHED);

<小时>

*更正,根据评论:文档有误,应该是SpreadsheetApp.BorderStyle.DASHED/DOTTED/SOLID,而不是Range.– 戈托弗里茨

这篇关于设置边框颜色 &amp;以编程方式在电子表格中设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆