Excel header and footer give additional information of an Excel sheet, such as the page number, author name, topic name and date etc. With the help of Spire.XLS, developers can easily add text header and footer into an excel spreadsheet. Sometimes, the font and size of the header and footer may be different with the font in the excel documents, and it makes the document in disorder. This article will demonstrate how to change the font and size for the text on excel header and footer.

Firstly, check the original font and size on Excel header and footer:

How to change the font and size for Excel header and footer in C#

By using Spire.XLS, we can easily set the new size and font for the header and footer text. Here comes to the steps of how to change the font and size for excel header and footer:

Step 1: Create an excel document and load the Excel with header and footer from file:

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Gets the first worksheet in the Excel file

Worksheet sheet = workbook.Worksheets[0];

Step 3: Set the new font and size for the header and footer

string text = sheet.PageSetup.LeftHeader;
//"Arial Unicode MS" is font name, "18" is font size
text = "&\"Arial Unicode MS\"&18 Header Footer Sample by Spire.XLS ";
sheet.PageSetup.LeftHeader = text;
sheet.PageSetup.RightFooter = text;

Step 4: Save the document to file and preview it

workbook.SaveToFile(@"..\Result.xlsx",ExcelVersion.Version2010);
System.Diagnostics.Process.Start(@"..\Result.xlsx");

Effective screenshot after changing the font and size for the header:

How to change the font and size for Excel header and footer in C#

Full codes:

using Spire.Xls;
namespace Changefontforheaderfooter
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            string text = sheet.PageSetup.LeftHeader;
            //"Arial Unicode MS" is font name, "18" is font size
            text = "&\"Arial Unicode MS\"&18 Header Footer Sample by Spire.XLS ";
            sheet.PageSetup.LeftHeader = text;
            sheet.PageSetup.RightFooter = text;
            //Save workbook and preview it
            workbook.SaveToFile(@"..\Result.xlsx",ExcelVersion.Version2010);
            System.Diagnostics.Process.Start(@"..\Result.xlsx");
        }
    }
}

Every time we create a plain table in a Word document, we may want to change the style of the table so as to make it more vivid and attractive. In our previous article, we have demonstrated how to set Word table formatting with custom style. However, if we do not have much time to do so, we can apply built-in table styles to own a better appearance within a few minutes. This article focuses on how to apply built-in table styles to existing Word tables using Spire.Doc with C#, VB.NET.

In the class of Spire.Doc.Table, it provides Table.ApplyStyle() method which enable us to easily change the layout of tables with default styles. As is shown below, here is a Word document that contains two plain tables in the first page. Let us see how we can format the table style with several lines of code.

Test File:

Apply Built-In Table Styles to Existing Word Tables in C#, VB.NET

Code Snippet:

Step 1: Create a new Word document and load the test file.

Document doc = new Document("table.docx", FileFormat.Docx2010);

Step 2: Get the two tables from document.

Section section = doc.Sections[0];
Table table1 = section.Tables[0] as Table;
Table table2 = section.Tables[1] as Table;

Step 3: Apply tables with built-in table styles separately.

table1.ApplyStyle(DefaultTableStyle.MediumShading1Accent2);
table2.ApplyStyle(DefaultTableStyle.MediumShading2Accent1);

Step 4: Save the file.

doc.SaveToFile("result.docx", FileFormat.Docx);

Output:

Apply Built-In Table Styles to Existing Word Tables in C#, VB.NET

Entire Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
namespace ApplyTableStyles
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document("table.docx", FileFormat.Docx2010);
            Section section = doc.Sections[0];
            Table table1 = section.Tables[0] as Table;
            Table table2 = section.Tables[1] as Table;

            table1.ApplyStyle(DefaultTableStyle.MediumShading1Accent2);
            table2.ApplyStyle(DefaultTableStyle.MediumShading2Accent1);
            doc.SaveToFile("result.docx", FileFormat.Docx);

        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace ApplyTableStyles
	Class Program

		Private Shared Sub Main(args As String())

			Dim doc As New Document("table.docx", FileFormat.Docx2010)
			Dim section As Section = doc.Sections(0)
			Dim table1 As Table = TryCast(section.Tables(0), Table)
			Dim table2 As Table = TryCast(section.Tables(1), Table)

			table1.ApplyStyle(DefaultTableStyle.MediumShading1Accent2)
			table2.ApplyStyle(DefaultTableStyle.MediumShading2Accent1)
			doc.SaveToFile("result.docx", FileFormat.Docx)

		End Sub
	End Class
End Namespace

Spire.PDFViewer FAQ

2014-10-23 08:56:00 Written by Koohji

Building Error

Q: When I drag and drop the PdfDocumentViewer control on the winform application and build the project, I get an error like this:

What should I do?

A: To get rid of this error, please delete "licenses.licx" file in Properties folder and rebuild the project.

page 254