Automatically resize columns in Google sheets

前端 未结 5 932
粉色の甜心
粉色の甜心 2021-02-14 11:46

I would like to have columns on google sheets automatically resize to fit my text, without me having to manually resize them after every entry. How do I do this?

相关标签:
5条回答
  • 2021-02-14 11:59

    Sounds like you want autoResizeColumn. Make an AppScript script and you can put

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

    Which will resize the specified column based off its contents.

    Run the function everytime you want to resize or put it in a trigger like onOpen().

    However, it seems to have a maximum size that it will change to.

    0 讨论(0)
  • 2021-02-14 12:01

    FYI, I don't know an automatic method. But you can do it at once by:

    • selecting desired columns from their headers
    • right-click anywhere on the selected area
    • Select Resize columns...... part from the menu
    • Select Fit to Data
    • Click OK

    And you are done.

    0 讨论(0)
  • 2021-02-14 12:06

    first of all, select the desired cells and then right-click on it(on the left side of the sheet, where numbers are written), choose the "resize cell" option from the GUI, and then select "fit to data" and click on ok button.

    0 讨论(0)
  • 2021-02-14 12:13

    FYI -- For those who don't want to delve into scripting, but want a way to do it faster, you can auto-resize all the columns at once, manually: Hit Cmd+A (or Ctrl+A in Windows) to select everything, then move the mouse to the border between any two column headers -- as if you wanted to resize that one manually-- the cursor changes to an arrow... and double click. Found this trick here.

    0 讨论(0)
  • 2021-02-14 12:15

    To make the column re-size fully automatic you an create this function, which will trigger every time you edit the contents of a cell:

    function onEdit(e) {
      e.range.getSheet ().autoResizeColumn (e.range.getColumn ());
    }
    

    Note that this trigger will only run in response to typing. Pasting and importing will not cause this trigger to run.

    If you want a function that will resize all columns in your active sheet, this one will do it:

    function resizeAllColumns () {
      var sheet = SpreadsheetApp.getActiveSheet();
      var dataRange = sheet.getDataRange();
      var firstColumn = dataRange.getColumn();
      var lastColumn = dataRange.getLastColumn();
      sheet.autoResizeColumns(firstColumn, lastColumn);
    }
    

    For convenience you can attach a keyboard shortcut to the function if you need to execute the manual function often.

    0 讨论(0)
提交回复
热议问题