如何更改“调整大小的行"从“适合数据"设置; “指定行高度,不是吗,无论如何我都希望该行的高度为21像素"? [英] How do I change the "Resize row" setting from "Fit to data" to "Specify row height, no really, I want this row to be 21 pixels tall no matter what"?

查看:95
本文介绍了如何更改“调整大小的行"从“适合数据"设置; “指定行高度,不是吗,无论如何我都希望该行的高度为21像素"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过:

var ss = SpreadsheetApp.openById('1-hcd6JWmWZ9MrSkt2_N8PXDGz4j-my-sheet-id');
var sheet = ss.getSheetByName('test');
sheet.setRowHeight(1, 21);

这在行为空的情况下有效,这是没有用的,因为为什么我会在非默认高度上有一个空行.

This works if the row is empty, which is useless since why would I have an empty row at the non-default height.

但是,即使它改变了行高,如果您手动调出调整行大小...",对话框中,它仍然设置为适合数据"而不是指定行高".

However, even though it changes the row height, if you manually bring up the "Resize rows..." dialog, it's still set to "Fit to data" instead of "Specify row height".

当结合有关Sheets的其他一些事实时,这非常令人沮丧.无论您的文本换行设置是什么,行高将始终适合数据".如果粘贴或setValue().并且,如果该行已经包含数据,则即使您在该行上显式地setHeight(),Sheets也会拒绝实际更改高度,而是让"Fit to data"适合如果可以调整行高,则始终优先.

This is pretty frustrating when combined with a couple other facts about Sheets. No matter what your text wrap settings are, row heights will always "Fit to data" if you paste or setValue(). And, if the row already contains data, even if you explicitly setHeight() on the row, Sheets will refuse to actually change the height, instead letting "Fit to data" always take precedence if it would adjust the row height.

我找不到任何方法来自动设置行数据,并保持行高,整洁,紧凑,有效的行高为21左右.

I can't find any way to automate setting row data and also keeping nice, clean, compact, efficient rows heights of 21 or so.

推荐答案

  • 您要将行高设置为21像素.
  • 您要将行高的条件设置为指定行高",而不是适合数据".
  • 您要使用Google Apps脚本.
  • 如果我的理解是正确的,那么如何使用Sheets API?在我的环境中,我还可以确认运行sheet.setRowHeight(1, 21)脚本时,行高的条件更改为适合数据".为了解决此问题,我想使用Sheets API.示例脚本如下.

    If my understanding is correct, how about using Sheets API? In my environment, also I could confirm that when the script of sheet.setRowHeight(1, 21) is run, the condition of row height changed to "Fit to data". In order to resolve this issue, I would like to use Sheets API. The sample script is as follows.

    使用此脚本时,请首先在Advanced Google Services上启用Sheets API.

    在此示例脚本中,1-hcd6JWmWZ9MrSkt2_N8PXDGz4j-my-sheet-id的电子表格中test工作表的第1行的高度更改为21个像素,并带有指定行高度".

    In this sample script, the height of row 1 of test sheet in the Spreadsheet of 1-hcd6JWmWZ9MrSkt2_N8PXDGz4j-my-sheet-id changes to 21 pixels with "Specify row height".

    var spreadsheetId = "1-hcd6JWmWZ9MrSkt2_N8PXDGz4j-my-sheet-id";
    var sheetName = "test";
    
    var ss = SpreadsheetApp.openById(spreadsheetId);
    var sheetId = ss.getSheetByName(sheetName).getSheetId();
    var resource = {
      "requests": [
        {
          "updateDimensionProperties": {
            "properties": {
              "pixelSize": 21
            },
            "range": {
              "dimension": "ROWS",
              "sheetId": sheetId,
              "startIndex": 0,
              "endIndex": 1
            },
            "fields": "pixelSize"
          }
        }
      ]
    };
    Sheets.Spreadsheets.batchUpdate(resource, spreadsheetId);
    

    注意:

    • 作为附加信息,当您要使用适合数据"时,可以使用电子表格的自动重尺寸标注请求.batchUpdate.
      • Advanced Google Services
      • spreadsheets.batchUpdate
      • UpdateDimensionPropertiesRequest
      • AutoResizeDimensionsRequest

      如果我误解了您的问题,而这不是您想要的结果,我深表歉意.

      If I misunderstood your question and this was not the result you want, I apologize.

      这篇关于如何更改“调整大小的行"从“适合数据"设置; “指定行高度,不是吗,无论如何我都希望该行的高度为21像素"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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