How To Make Excel Cells Expand To Fit Text Automatically

In this article, I will show you how to make an excel cell expand it’s width and height to fit the input text width or height automatically.

1. Make Excel Cell Expand To Fit Text Size Method 1.

  1. Put the mouse pointer at the cell’s column heading right border or row heading lower border that you want to expand.
  2. When the mouse pointer change to a left-right or up-down arrow, double click it.
  3. Then you can find the cell has been expanded to fit the text size.

2. Make Excel Cell Expand To Fit Text Size Method 2.

  1. Select the excel cell that you want to expand to fit the text size.
  2. Click Home —> Format —> AutoFit Row Height / AutoFit Column Width menu item to expand it.
  3. The above menu item has a shortcut key that is Alt + H( Home tab) + O ( Format menu ) + A ( AutoFit Row Height ) / I (AutoFit Column Width)

3. Expand Multiple Excel Cell To Fit Text.

  1. Sometimes you need to expand multiple excel cells to make them fit the text content, you can follow the below steps to do it.
  2. Select multiple columns or rows.
  3. Or press Ctrl + A to select the whole excel worksheet.
  4. Then you can follow method 1 or 2 to expand all the columns or rows.

4. How To Make An Excel Cell Wrap Text Content Automatically.

  1. In Microsoft Excel, you can make an Excel cell wrap it’s content automatically so that it will display multiple lines of the cell content in the cell.
  2. You can even enter a line-break manually to separate the different textual content in an Excel cell.
  3. To do this, you need to first select the cells, then click the Home(tab) —> Alignment(group) —> Wrap Text item.
  4. The above action also has a shortcut key that is Alt + H + W.
  5. Now the cell will wrap its text data to match the column width change automatically, when you drag the edge of the Excel cell to increase/decrease its width, the text line in it will automatically adjust its length also.

5. How To Input Line Break In One Excel Cell To Input Text In A New Line.

  1. You can input a line break to enter the text in a new line in an excel cell following the below steps.
  2. Select the Excel cell by double click it.
  3. Click the position that you want to enter a new line break.
  4. Press shortcut Alt + Enter, then you can input text in the next new line after the current position.

6. How To Make Text Auto Fit Excel Cell’s Width & Height Programmatically In C#.

6.1 Question1.

  1. I write a c# program, in that program it will read data from a SQL Server database table, and then write the data to an .csv file. The c# source code is sw.Write(string.Format(“=\”{0}\””, drow[i].ToString()));.
  2. But when I open the .csv file in Microsoft excel, I find the table data in the excel cell is not auto-fit the width & height of the cell.
  3. How can I make the text data auto-fit the excel cell width & height programmatically? I use c# language, thanks a lot.

6.2 Answer1.

  1. You can first load your .csv file into an instance of Microsoft.Office.Interop.Excel.
  2. Then run the code Excel.Rows.AutoFit (Range.Rows.AutoFit()) to auto fit the height.
  3. And run the code Excel.Columns.AutoFit (Range.Columns.AutoFit()) to auto fit the width.

7. How To Expand Excel Rows & Columns Text Automatically Using Apache POI.

7.1 Question1.

  1. My java project uses Apache POI to create an excel file and write text data to the excel file spreadsheet.
  2. But when I open the created excel spreadsheet, I find in some cells, the text does not show entirely because the text is too long than the cell width.
  3. What I want is that the long text cell will expand the cell automatically so that we can see all the text in the cell at the first glance. But now I have to drag the cell border to show the hidden text.

7.2 Answer1 (2022/05/10).

  1. You can use the excel worksheet object’s autoSizeColumn(columnNumber) method to auto-expand the cell column.
  2. But this method should be invoked after you load the text data into the excel worksheet, if you call it before populating the text data into the cell, it does not take effect.
  3. Below is the example source code, you can see the code comments to learn it.
    // This method can expand all the excel sheet columns in an excel workbook.
    public void autoSizeColumns(Workbook wb) {
        // Get the sheet number in an excel workbook.
        int sheetCount = wb.getNumberOfSheets();
        // Loop in all the excel sheets.
        for (int i = 0; i < sheetCount; i++) {
        	// Get the sheet object by the sheet number.
            Sheet ws = wb.getSheetAt(i);
            // Get the rows count of the sheet. 
            int numberOfRows = ws.getPhysicalNumberOfRows();
            // If the sheet has rows.
            if (numberOfRows > 0) {
            	// Get the first row object of the work sheet.
            	int firstRowNumber = sheet.getFirstRowNum();
                Row row = sheet.getRow(firstRowNumber);
                // Get the row's cell iterator object.
                Iterator<Cell> cellIt = row.cellIterator();
                // Iterate all the row cells.
                while (cellIt.hasNext()) {
                	// Get one cell object. 
                    Cell cell =;
                    // Get the cell's column index.            
                    int columnIndex = cell.getColumnIndex();
                    // Call the excel sheet object's autoSizeColumn(columnIndex) method to auto expand the column.

8. Excel Courses.

  1. You can click the link Top Hot Excel Books On Amazon to go to Amazon to find the hot excel books and learn excel skills.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.