Articles in this section
Category / Section

Change the orientation of text in C#, VB.NET in WinForms Excel

6 mins read

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 assign different orientations to text in an Excel document.

Text orientation can be changed by assigning rotation to the cell through Rotation property accessible under CellStyle of IRange interface.


Steps to change the orientation of text, programmatically:

  1. Create a new C# console application project.

Create a new C# console application project

Create a new C# console application project

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

Install NuGet package to the project

Install NuGet package to the project

  1. Include the following namespaces in Program.cs file.

C#

using Syncfusion.XlsIO;

 

VB.NET

Imports Syncfusion.XlsIO

 

  1. Include the following code snippet in main method of Program.cs file to set the orientation of text.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    //Initialize the Excel application object
    IApplication application = excelEngine.Excel;
 
    //Create a new Excel Workbook
    IWorkbook workbook = application.Workbooks.Create(1);
 
    //Get the first worksheet in workbook into IWorksheet
    IWorksheet worksheet = workbook.Worksheets[0];
 
    //Set the text orientation
    worksheet.Range["B3"].CellStyle.Rotation = 35;
    worksheet.Range["E3"].CellStyle.Rotation = 90;
 
    //Assign text in worksheet
    worksheet.Range["B3"].Text = "Text Orientation is 35 degrees";
    worksheet.Range["B3"].AutofitColumns();
    worksheet.Range["E3"].Text = "Text Orientation is 90 degrees";
    worksheet.Range["E3"].AutofitColumns();
 
    //Save the Excel document
    workbook.SaveAs("Output.xlsx");
}

 

VB.NET

Using excelEngine As ExcelEngine = New ExcelEngine
    'Initialize the Excel application object
    Dim application As IApplication = excelEngine.Excel
 
    'Create a new Excel Workbook
    Dim workbook As IWorkbook = application.Workbooks.Create(1)
 
    'Get the first worksheet in workbook into IWorksheet
    Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
    'Set the text orientation
    worksheet.Range("B3").CellStyle.Rotation = 35
    worksheet.Range("E3").CellStyle.Rotation = 90
 
    'Assign text in worksheet
    worksheet.Range("B3").Text = "Text Orientation is 35 degrees"
    worksheet.Range("B3").AutofitColumns()
    worksheet.Range("E3").Text = "Text Orientation is 90 degrees"
    worksheet.Range("E3").AutofitColumns()
 
    'Save the Excel document
    workbook.SaveAs("Output.xlsx")
End Using

 

A complete working sample of how to set the orientation of text can be downloaded from TextOrientation.zip.

By executing the program, you will get the output Excel file as follows.

Change the orientation of text

Output Excel document

Take a moment to peruse the documentation, where you will find other options like row and column style, applying number formats to cells, cell text alignmentmerging and unmerging of cells, fontcolor and border setting, HTML string formatting and Rich-Text formatting 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 trial message.


 

Conclusion

I hope you enjoyed learning about how to change the orientation of text in C#, VB.NET in WinForms Excel.

You can refer to our .NET Excel library page to know about its other groundbreaking feature representations and documentation, 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  feedbackportal. 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 (0)
Please sign in to leave a comment
Access denied
Access denied