Articles in this section

How to Set multiline text in Excel header and footer using C#, VB.NET?

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

This article explains how to set multiline text in Excel headers and footers using C# and VB.NET.

Include the following namespace in the Program.cs file.

C#

using Syncfusion.XlsIO;

VB.NET

Imports Syncfusion.XlsIO

Use the following code snippet for setting multiline text in Excel headers and footers.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    IWorkbook workbook = application.Workbooks.Create(1);
    IWorksheet worksheet = workbook.Worksheets[0];

    //Format header with multiline text
    worksheet.PageSetup.CenterHeader = "Monthly Sales Report\nJanuary";

    //Format footer with multiline text
    worksheet.PageSetup.CenterFooter = "Page &P\nGenerated on &D";

    #region Save
    //Saving the workbook
    FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
    workbook.SaveAs(outputStream);
    #endregion

    //Dispose streams
    outputStream.Dispose();
}

VB.NET

Using excelEngine As New ExcelEngine()
    Dim application As IApplication = excelEngine.Excel
    application.DefaultVersion = ExcelVersion.Xlsx

    Dim workbook As IWorkbook = application.Workbooks.Create(1)
    Dim worksheet As IWorksheet = workbook.Worksheets(0)

    'Format header with multiline text
    worksheet.PageSetup.CenterHeader = "Monthly Sales Report" & vbLf & "January"

    'Format footer with multiline text
    worksheet.PageSetup.CenterFooter = "Page &P" & vbLf & "Generated on &D"

    'Saving the workbook
    workbook.SaveAs("Output.xlsx")
End Using  

You can get the complete sample for setting multiline text in Excel headers and footers from

Conclusion

I hope you enjoyed learning about how to set multiline text in Excel header and footer using C#, VB.NET.

You can refer to our .NET Core XIsIO feature tour page to learn about its other groundbreaking features. Explore our .NET Core XIsIO documentation and .NET Core XIsIO demo to understand how to manipulate data in Excel documents.

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, 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 (0)
Access denied
Access denied