Link Search Menu Expand Document

Add Header and Footer - VB.NET

Spreadsheet SDK sample in VB.NET demonstrating ‘Add Header and Footer’

Imports System.Diagnostics
Imports System.IO
Imports Bytescout.Spreadsheet

Class Program
    Friend Shared Sub Main(ByVal args As String())

        ' Create new Spreadsheet object
        Dim doc As New Spreadsheet()

        ' Add worksheet
        Dim worksheet As Worksheet = doc.Worksheets.Add()

        ' 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."
        ' Delete output file if exists
        If File.Exists("output.xls") Then
        End If

        ' Save document

        ' Close spreadsheet

        ' Open generated XLS document in default application

    End Sub
End Class

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK