ByteScout Spreadsheet SDK - C# - Add Header and Footer - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout Spreadsheet SDK – C# – Add Header and Footer

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – C# – Add Header and Footer

ByteScout Spreadsheet SDK – C# – Add Header and Footer

Program.cs

using System;
using System.Diagnostics;
using System.IO;
using Bytescout.Spreadsheet;

namespace AddHeaderAndFooter
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
			    // Create new Spreadsheet object
                Spreadsheet spreadsheet = new Spreadsheet();

                // Add new worksheet
                Worksheet worksheet = spreadsheet.Workbook.Worksheets.Add("Sample");

                // Add headers:

                // add date as left header
                worksheet.PageSetup.LeftHeader = "&D";
                // add label with custom font as center header
                worksheet.PageSetup.CenterHeader = "&\"Verdana,bold\"&14Laws && Rights";
                // add time as right header
                worksheet.PageSetup.RightHeader = "&T";

                // Add footers:

                // add file name as left footer
                worksheet.PageSetup.LeftFooter = "&F";
                // add "page of pages" indicator as center footer
                worksheet.PageSetup.CenterFooter = "&P/&N";
                // add simple text as right footer
                worksheet.PageSetup.RightFooter = "Right footer";

                // Add worksheet content
                worksheet.Cell(1, 1).Value = "Click Print Preview to see headers and footers.";

                // Save it as XLS
                if (File.Exists("Output.xls"))
                    File.Delete("Output.xls");
                spreadsheet.SaveAs("Output.xls");

                // Close the document
                spreadsheet.Close();

                // Open output XLS file
                Process.Start("Output.xls");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("\nPress any key to exit...");
                Console.ReadKey();
            }
        }
    }
}


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next