【问题标题】:Is there a way within a Google Apps Script to set a row height to fit the dataGoogle Apps 脚本中有没有办法设置行高以适应数据
【发布时间】:2017-08-09 21:09:27
【问题描述】:

在 Google 表格中,选择一系列行并右键单击其中一个后,行高下有一个适合数据的选项。我想在脚本中执行此操作。

我所有的搜索都说不,但我充满希望。列被很好地覆盖,但行似乎没有被覆盖。

谢谢。

【问题讨论】:

标签: google-apps-script google-sheets-api


【解决方案1】:

据我所知,不可能让行自动适应数据,这只能对带有autoResizeColumn() 的列进行。

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

sheet.getRange('a1').setValue('Whenever it is a damp, drizzly November in my soul...');

// Sets the first column to a width which fits the text
sheet.autoResizeColumn(1);

但是,如果您知道数据将占用多少空间,则可以使用setRowHeight()。我认为这是您对行的唯一选择,列似乎是自动调整的首选部分。

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

// Sets the first row to a height of 200 pixels
sheet.setRowHeight(1, 200);

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    这是一个老问题,但似乎已经添加了此功能。

    现在您可以使用autoResizeRows() 函数。

    文档解释得很好。

    https://developers.google.com/apps-script/reference/spreadsheet/sheet#autoResizeRows(Integer,Integer)

    【讨论】:

    • 给出大于 26 的值时会出错。 “例外:那些列超出范围。”如何解决?
    猜你喜欢
    • 2021-12-16
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    相关资源
    最近更新 更多