Articles in this section
Category / Section

How to set a line break in an Excel cell using C#, VB.NET?

1 min read

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents and also, converts Excel documents to PDF files.

This article illustrates how to make a line break inside an Excel cell. The following complete code snippet explains this.

C#

using System;
using Syncfusion.XlsIO;
 
namespace LineBreak
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;
 
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
 
                worksheet.Range["A1"].CellStyle.WrapText = true;
                worksheet.Range["A1"].Text = String.Format("Hello\nWorld");
 
                workbook.SaveAs("Output.xlsx");
            }
        }
    }
}

 

A working sample can be downloaded from LineBreak.zip

On executing the sample, you will get the output as follows.

Line Break

Line Break

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like conditional formatting, worksheet calculations through formulas, adding charts in worksheet or workbook, organizing and analyzing data through tables and Pivot Tables, appending multiple records to worksheet using template markers, and most importantly PDF and Image conversions etc. with code examples.

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

Note:

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 trail message



 

Conclusion

I hope you enjoyed learning about how we can set line break in an Excel cell in C#, VB.NET.

You can refer to our WinForms word feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms word example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsdirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied