We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set row height when using WrapText?

Platform: WinForms |
Control: XlsIO


Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can perform row/column manipulations in C# and VB.NET. This article explains how to set row height when WrapText is applied.

When a long text is entered in Excel cells, applying WrapText to that cell will fit the row height in Microsoft Excel. However, in XlsIO the row height will not be updated if WrapText is applied programmatically. To fit the row to the content, it is recommended to invoke the AutoFitRows() method, explicitly. This will return the updated row height. Let’s see how to do this.

Steps to set row height when using WrapText, programmatically:

Step 1: Create a new C# console application project.

Create C# console application

Create a new C# console application

Step 2: Install Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

Install XlsIO NuGet package

Install XlsIO NuGet package


Step 3: Include the following namespaces in the Program.cs file.


using Syncfusion.XlsIO;



Imports Syncfusion.XlsIO


Step 4: Use the following code snippet to set row height when using WrapText in C# and VB.NET.


using (ExcelEngine excelEngine = new ExcelEngine())
    //Instantiate the application object
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2016;
    //Create a new workbook
    IWorkbook workbook = application.Workbooks.Create(1);
    //Access the first worksheet
    IWorksheet worksheet = workbook.Worksheets[0];
    //Set a sample text in cell "A1"
    worksheet["A1"].Text = "This cell contains sample text";
    //Set wrap text
    worksheet["A1:C8"].WrapText = true;
    //Set text in cells "A3" and "C1"
    worksheet["A3"].Text = "This cell contains sample text This cell contains sample text";
    worksheet["C1"].Text = "This cell contains sample text This cell contains sample text";
    //Set auto-fit rows to update the row heights
    //Get the updated row height
    double rowHeight = worksheet["A1"].RowHeight;
    //Save the workbook



Using excelEngine As ExcelEngine = New ExcelEngine()
    'Instantiate the application object
    Dim application As IApplication = excelEngine.Excel
    application.DefaultVersion = ExcelVersion.Excel2016
    'Create a new workbook
    Dim workbook As IWorkbook = application.Workbooks.Create(1)
    'Access the first worksheet
    Dim worksheet As IWorksheet = workbook.Worksheets(0)
    'Set a sample text in cell "A1"
    worksheet("A1").Text = "This cell contains sample text"
    'Set wrap text
    worksheet("A1:C8").WrapText = True
    'Set text in cells "A3" and "C1"
    worksheet("A3").Text = "This cell contains sample text This cell contains sample text"
    worksheet("C1").Text = "This cell contains sample text This cell contains sample text"
    'Set auto-fit rows to update the row heights
    'Get the updated row height
    Dim rowHeight As Double = worksheet("A1").RowHeight
    'Save the workbook
End Using


A complete working example of how to update row height when using WrapText in C# and VB.NET can be downloaded from Autofit wrapped text.zip.

Refer here to explore the rich set of Syncfusion Excel (XlsIO) library features.

See Also:

How to convert Excel to PDF in C#, VB.NET

How to Export and Save Excel Chart as Image

How to set column width and row height?

Insert new row with previous row format in Excel using C#

Delete Excel rows and columns in C#, VB.NET

How to set Freeze panes in Excel using C#, VB.NET?

Sort Excel pivot table data by row and column fields in C# using XlsIO

Is it possible to AutoFit a row that contains a cell merged with cells in other rows?


Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trial message.


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment
Stephan Wagner
Jan 28, 2015
Is this still the valid answer? If yes, could you provide the name/location of the helper classe since the mentioned URL is not valid anymore? Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile