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.
- Put the mouse pointer at the cell’s column heading right border or row heading lower border that you want to expand.
- When the mouse pointer change to a left-right or up-down arrow, double click it.
- 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.
- Select the excel cell that you want to expand to fit the text size.
- Click Home —> Format —> AutoFit Row Height / AutoFit Column Width menu item to expand it.
- 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.
- Sometimes you need to expand multiple excel cells to make them fit the text content, you can follow the below steps to do it.
- Select multiple columns or rows.
- Or press
Ctrl + A
to select the whole excel worksheet. - 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.
- 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.
- You can even enter a line-break manually to separate the different textual content in an Excel cell.
- To do this, you need to first select the cells, then click the Home(tab) —> Alignment(group) —> Wrap Text item.
- The above action also has a shortcut key that is Alt + H + W.
- 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.
- You can input a line break to enter the text in a new line in an excel cell following the below steps.
- Select the Excel cell by double click it.
- Click the position that you want to enter a new line break.
- 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.
- I write a c# program, in that program, it will read data from a SQL Server database table, and then write the data to a .csv file. The c# source code is sw.Write(string.Format(“=\”{0}\””, drow[i].ToString()));.
- 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.
- 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.
- You can first load your .csv file into an instance of Microsoft.Office.Interop.Excel.
- Then run the code Excel.Rows.AutoFit (Range.Rows.AutoFit()) to auto fit the height.
- And run the code Excel.Columns.AutoFit (Range.Columns.AutoFit()) to auto fit the width.