Automates the adjustment of row heights in Google Sheets, enhancing readability and visual appeal by providing adequate padding for cell contents.

This tool optimizes row height in Google Sheets, addressing the shortcomings of the built-in Resize row and Fit to data features. The built-in functionality often results in rows that are too short when they contain a single line of text, and lacks sufficient padding for rows with multiple lines, making them hard to read. This tool adjusts row height for optimal readability and aesthetics based on pre-defined conditions, saving time and improving understanding in consolidated documents.
Fit to Data Feature
Figure: Fit to Data Feature in Google Sheets
Fit to Data Result
Figure: Fit to Data Result in Google Sheets
  • A Google account with access to Google Sheets.
  • A foundational understanding of Google Sheets and Google Apps Script.
  1. Access a Sample Google Sheet: Begin by opening the Sample Google Sheet

    *Note: The samples provided are merely illustrative, showcasing course schedule for an educational institution.

  2. Copy the Google Sheet: Make a copy of the Google Sheet to create your personalized version.
  3. Customize Constant Variables: Adjust the following variables in Google Apps Script to suit your needs:
    • AVERAGE_CHART_WIDTH: This represents the average width of a character in your sheet. The pre-set value is "4.5". This might change based on which font to be used.
    • BASE_ROW_HEIGHT: The base height of a row with a single line of text. Pre-set value is "25".
    • ADDITIONAL_ROW_HEIGHT: The additional height for each additional line of text. Pre-set value is "20".
    • Fit to Data Feature
      Figure: Customize Constant Variables
  4. Authorization: The first time you run the script, it will ask for your permission to access certain data. If you're using a free Gmail account, you might see a warning that says Not Verified by Google. Don't worry about this warning - you still need to give permission for the script to work. The script is yours alone, and it won't share any data outside of Google, unless you choose to share your Google Sheet. The only data it might send outside of Google is website status codes, for monitoring purposes.
  1. Select Custom Menu > Adjust Row Heights

    This initiates a process that adjusts the height of each row in a specified sheet, starting from a user-defined row number.

    Here's the step-by-step logic:

    • Input Sheet Name and Starting Row: A dialog prompts you to input the name of the sheet and the starting row number.
    • Data Retrieval: The script retrieves the data from the specified sheet and starting row, and gets the widths of all columns in the sheet.
    • Row Height Calculation: For each row, the script calculates the line count for each cell, taking into account the physical width of the text and any manual line breaks. It then determines the largest line count among all cells in the row.
    • Height Adjustment: The row height is adjusted based on the largest line count. The height is calculated using a base height for a single line and an additional height for each additional line.

    This function ensures that the row height accommodates the cell with the most content, providing a cleaner and more organized view of your data.

Please note that your use of this website is subject to the Terms and Conditions.

You can find the source code for this tool on Github. Click HERE .

Last updated: May 5, 2024