.NET (1322)
Children categories
An annotation is a note or comment added to a pdf file, it can be an explanation or a reference to the specific part of the original data. Add annotations can make the file becomes easier to understand for readers.
Spire.PDF enables us to add, edit and delete annotation from a PDF document. This section will demonstrate how to add text annotation and edit annotation in pdf from WPF Applications using Spire.PDF for WPF.
This is the effective screenshot after adding and editing annotation:

After editing, the text content of the annotation changed from “Demo” to “This is an annotation”.
At first, use the following namespace:
using System.Drawing; using System.Windows; using Spire.Pdf; using Spire.Pdf.Annotations; using Spire.Pdf.Graphics;
Then refer to the detail steps below:
Step 1: Create a new PDF document and add a new page to it.
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add();
Step 2: Draw text in the page and set text font, font size, color and location.
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 15); string text = "Spire.PDF"; PdfSolidBrush brush = new PdfSolidBrush(Color.DeepSkyBlue); PointF point = new PointF(50, 100); page.Canvas.DrawString(text, font, brush, point);
Step 3: Add annotation.
First, create a text annotation using the PdfTextMarkupAnnotation class:
PdfTextMarkupAnnotation annotation = new PdfTextMarkupAnnotation("Author", "Demo", text, new PointF(0, 0), font);
There are four parameters of the annotation:
“Author”: the author of annotation. “Demo”: text content of annotation. text: the text which will be marked. new PointF(0, 0): not supported at present. font: the font of the text which will be marked.
Second, Set Border, TextMarkupColor and location of the annotation:
annotation.Border = new PdfAnnotationBorder(0.50f); annotation.TextMarkupColor = Color.LemonChiffon; annotation.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left);
Third, add the annotation to the specified page:
(page as PdfNewPage).Annotations.Add(annotation);
If you need to edit the text of the annotation, then you can use following code:
(page as PdfNewPage).Annotations[0].Text = "This is an annotation";
Step 4: Save and launch the file.
doc.SaveToFile("Annotation.pdf");
System.Diagnostics.Process.Start("Annotation.pdf");
Full codes:
private void button1_Click(object sender, RoutedEventArgs e)
{
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 15);
string text = "Spire.PDF";
PdfSolidBrush brush = new PdfSolidBrush(Color.DeepSkyBlue);
PointF point = new PointF(50, 100);
page.Canvas.DrawString(text, font, brush, point);
//Add annotation
PdfTextMarkupAnnotation annotation = new PdfTextMarkupAnnotation("Author", "Demo", text, new PointF(0, 0), font);
annotation.Border = new PdfAnnotationBorder(0.50f);
annotation.TextMarkupColor = Color.LemonChiffon;
annotation.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left);
(page as PdfNewPage).Annotations.Add(annotation);
//Edit the text of the annotation
(page as PdfNewPage).Annotations[0].Text = "This is an annotation";
doc.SaveToFile("Annotation.pdf");
System.Diagnostics.Process.Start("Annotation.pdf");
}
Whenever you are working with lots of data, it can be difficult to compare information in your workbook. You may want to see certain rows or columns all the time in your worksheet, especially header cells. By freezing rows or columns in place, you can keep rows or columns visible while scrolling through the rest of the worksheet.
In the following sections, I will demonstrate how to freeze Excel panes in WPF.
Step 1: Initialize a new instance of Workbook class. Load the word document from the file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("SalesReport.xlsx");
Step 2: In our example, my workbook has several worksheets. We want to check the data from the second worksheet. Therefore, we select the second worksheet.
Worksheet sheet = workbook.Worksheets[1];
Step 3: In this case, we want to fix the first two rows and the leftmost column. The row and column will be frozen in place, as indicated by the solid grey line.
sheet.FreezePanes(2, 1);
Step 4: Save the workbook and launch the file.
workbook.SaveToFile("SalesReport Result.xlsx");
System.Diagnostics.Process.Start("SalesReport Result.xlsx");
Effective screenshot:

Full Codes:
using System.Windows;
using Spire.Xls;
namespace SalesReport
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//Load Excel File
Workbook workbook = new Workbook();
workbook.LoadFromFile("SalesReport.xlsx");
//Select the second worksheet
Worksheet sheet = workbook.Worksheets[1];
//Select to freeze the first two rows and the leftmost column
sheet.FreezePanes(3, 2);
//Save and Launch
workbook.SaveToFile("SalesReport Result.xlsx");
System.Diagnostics.Process.Start("SalesReport Result.xlsx");
}
}
}
Imports System.Windows
Imports Spire.Xls
Namespace SalesReport
'''
''' Interaction logic for MainWindow.xaml
'''
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
'Load Excel File
Dim workbook As New Workbook()
workbook.LoadFromFile("SalesReport.xlsx")
'Select the second worksheet
Dim sheet As Worksheet = workbook.Worksheets(1)
'Select to freeze the first two rows and the leftmost column
sheet.FreezePanes(3, 2)
'Save and Launch
workbook.SaveToFile("SalesReport Result.xlsx")
System.Diagnostics.Process.Start("SalesReport Result.xlsx")
End Sub
End Class
End Namespace
A formula is an expression which performs calculations or other actions on the data in your worksheet. Using Spire.XLS, programmers can easily add, modify and calculate formulas in Excel cells. This guide will present how to add commonly used formulas to Excel with C# in WPF application.
Spire.XLS provides a class named CellRange, containing properties such as Formula, FormulaValue and HasFormula which allow users to work with formulas in specific cells. For adding a formula, the syntax could be as easy as follows:
sheet.Range[int row, int column].Formula= "=NOW()";
Apart from adding a formula for date and time, Spire.XLS also supports text, math, logical, statistical, lookup, reference and etc. Following section shows a list of over 40 formula examples (partially shown in the below screenshot) created by Spire.XLS.

Entire Code:
using Spire.Xls;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
int currentRow = 1;
string currentFormula = string.Empty;
sheet.SetColumnWidth(1, 32);
sheet.SetColumnWidth(2, 16);
sheet.SetColumnWidth(3, 16);
sheet.Range[currentRow++, 1].Value = "Examples of formulas :";
sheet.Range[++currentRow, 1].Value = "Test data:";
CellRange range = sheet.Range["A1"];
range.Style.Font.IsBold = true;
range.Style.FillPattern = ExcelPatternType.Solid;
range.Style.KnownColor = ExcelColors.LightGreen1;
range.Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Medium;
//test data
sheet.Range[currentRow, 2].NumberValue = 7.3;
sheet.Range[currentRow, 3].NumberValue = 5; ;
sheet.Range[currentRow, 4].NumberValue = 8.2;
sheet.Range[currentRow, 5].NumberValue = 4;
sheet.Range[currentRow, 6].NumberValue = 3;
sheet.Range[currentRow, 7].NumberValue = 11.3;
sheet.Range[++currentRow, 1].Value = "Formulas"; ;
sheet.Range[currentRow, 2].Value = "Results";
range = sheet.Range[currentRow, 1, currentRow, 2];
//range.Value = "Formulas";
range.Style.Font.IsBold = true;
range.Style.KnownColor = ExcelColors.LightGreen1;
range.Style.FillPattern = ExcelPatternType.Solid;
range.Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Medium;
//str.
currentFormula = "=\"hello\"";
sheet.Range[++currentRow, 1].Text = "=\"hello\"";
sheet.Range[currentRow, 2].Formula = currentFormula;
sheet.Range[currentRow, 3].Formula = "=\"" + new string(new char[] { '\u4f60', '\u597d' }) + "\"";
//int.
currentFormula = "=300";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
// float
currentFormula = "=3389.639421";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
//bool.
currentFormula = "=false";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
currentFormula = "=1+2+3+4+5-6-7+8-9";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
currentFormula = "=33*3/4-2+10";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
// sheet reference
currentFormula = "=Sheet1!$B$3";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
// sheet area reference
currentFormula = "=AVERAGE(Sheet1!$D$3:G$3)";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
// Functions
currentFormula = "=Count(3,5,8,10,2,34)";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
currentFormula = "=NOW()";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow, 2].Formula = currentFormula;
sheet.Range[currentRow, 2].Style.NumberFormat = "yyyy-MM-DD";
currentFormula = "=SECOND(11)";
sheet.Range[++currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MINUTE(12)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MONTH(9)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=DAY(10)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=TIME(4,5,7)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=DATE(6,4,2)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=RAND()";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=HOUR(12)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MOD(5,3)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=WEEKDAY(3)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=YEAR(23)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=NOT(true)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=OR(true)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=AND(TRUE)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=VALUE(30)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=LEN(\"world\")";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MID(\"world\",4,2)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=ROUND(7,3)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=SIGN(4)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=INT(200)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=ABS(-1.21)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=LN(15)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=EXP(20)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=SQRT(40)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=PI()";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=COS(9)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=SIN(45)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MAX(10,30)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=MIN(5,7)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=AVERAGE(12,45)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=SUM(18,29)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=IF(4,2,2)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
currentFormula = "=SUBTOTAL(3,Sheet1!B2:E3)";
sheet.Range[currentRow, 1].Text = currentFormula;
sheet.Range[currentRow++, 2].Formula = currentFormula;
workbook.SaveToFile(@"..\..\Sample.xls");
System.Diagnostics.Process.Start(@"..\..\Sample.xls");
}
}
}
To view the large amount of Excel data's easily, Spire.XLS for .NET supports create Pivot table and add excel table with filters. Spire.XLS also offers a method of pivotTable.ReportFilters.Add(); to enable developers to add the report filter to the pivot table.
This article will show you how to add a report filter to the Excel Pivot table in C#.
Note: Before Start, please download the latest version of Spire.XLS and add Spire.xls.dll in the bin folder as the reference of Visual Studio.
Firstly, please check the original screenshot of excel pivot table.

Step 1: Create a new workbook and load from file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Step 2: Get the PivotTable from the Excel worksheet.
Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable pivotTable = workbook.Worksheets["Pivot Table"].PivotTables[0] as Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable;
Step 3: Add a filter to the pivot table.
PivotReportFilter filter = new PivotReportFilter("JAN", true);
pivotTable.ReportFilters.Add(filter);
Step 4: Save the document to file and launch to preview it.
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("result.xlsx");
Effective screenshot after add a filter to the pivot table:

Full codes:
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.PivotTables;
namespace AddReportFilter
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable pivotTable = workbook.Worksheets["Pivot Table"].PivotTables[0] as Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable;
PivotReportFilter filter = new PivotReportFilter("JAN", true);
pivotTable.ReportFilters.Add(filter);
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("result.xlsx");
}
}
}
Generally we add predefined information or insert elements such as data, time and file name to Excel header or footer for printing purpose. Header or footer can be manually inserted or modified in Page Layout View or from Page Setup dialog box.
This article will present how to insert header and footer at runtime using Spire.XLS for WPF. Spire.XLS provides a class of PageSetup that contains all the page setup settings including header and footer, and a set of script commands that are used to set header and footer formatting.
Script Commands:
| Commands | Description |
| &G | A picture |
| &D | The current data |
| &T | The current time |
| &A | Worksheet name |
| &F | File name |
| &B | Make text bold |
| &I | Italicize text |
| &<Font name> | Font name. For example: &"Arial" |
| &K<Html color code> | Font color. For example: &KFFFFF0 |
Code Snippets:
Step 1: Initialize a new instance of Workbook class and get the first sheet from workbook.
Workbook wb = new Workbook(); Worksheet sheet = wb.Worksheets[0];
Step 2: Insert header text with formatting (specified font name, size and color) to the left part of Excel header.
sheet.PageSetup.LeftHeader ="&\"Showcard Gothic\"&14&K8B2252 Header and Footer Sample";
Step 3: Insert footer with formatting to the center part of Excel footer.
sheet.PageSetup.CenterFooter = "&B Copyright © 2016 e-iceblue. All Rights Reserved.";
Step 4: Save and launch the file.
wb.SaveToFile(@"..\Sample.xls"); System.Diagnostics.Process.Start(@"..\Sample.xls");
Output:
Header

Footer

Full Code:
using System.Drawing;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
sheet.PageSetup.LeftHeader = "&\"Showcard Gothic\"&14&K8B2252 Header and Footer Sample";
sheet.PageSetup.CenterFooter = "&B Copyright © 2016 e-iceblue. All Rights Reserved.";
wb.SaveToFile(@"..\Sample.xls");
System.Diagnostics.Process.Start(@"..\Sample.xls");
}
}
}
Imports System.Drawing
Imports System.Windows
Namespace WpfApplication1
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim wb As New Workbook()
Dim sheet As Worksheet = wb.Worksheets(0)
sheet.PageSetup.LeftHeader = "&""Showcard Gothic""&14&K8B2252 Header and Footer Sample"
sheet.PageSetup.CenterFooter = "&B Copyright © 2016 e-iceblue. All Rights Reserved."
wb.SaveToFile("..\Sample.xls")
System.Diagnostics.Process.Start("..\Sample.xls")
End Sub
End Class
End Namespace
We often use header to the PDF file to give additional information to the PDF file. With Spire.PDF for WPF, developers can easily use the method SetDocumentTemplate() to create a PDF template that only contains header text and header image. By invoking this method, the template will be applied to all pages in your PDF document. This article will demonstrate how to add a header to PDF in C# on WPF applications.
Note: Before Start, please download the latest version of Spire.PDF and add Spire.Pdf.Wpf.dll in the bin folder as the reference of Visual Studio.
Step 1: Create a new PDF document, set its margin and load from file.
PdfDocument doc = new PdfDocument();
doc.PageSettings.Margins.All = 0;
PdfPageBase page = null;
PdfDocument original = new PdfDocument();
original.LoadFromFile("Test.pdf");
Step 2: Create a SetDocumentTemplate() method to add header text.
SetDocumentTemplate(doc, PdfPageSize.A4, original.PageSettings.Margins);
Step 3: Traverse every page of the original PDF document and create a new page with the original contents.
foreach (PdfPageBase origianlPage in original.Pages)
{
page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height));
origianlPage.CreateTemplate().Draw(page, 0, -(original.PageSettings.Margins.Top));
}
Step 4: Save the document to file and launch to preview it.
doc.SaveToFile("output.pdf");
System.Diagnostics.Process.Start("output.pdf");
Step 5: Details of how to add the header text to the PDF.
private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
{
PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, margin.Top);
topSpace.Foreground = true;
doc.Template.Top = topSpace;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Trebuchet MS", 14f, System.Drawing.FontStyle.Italic));
String label = "This is a PDF text header";
SizeF size = font1.MeasureString(label);
float y = 0;
float x = 0;
topSpace.Graphics.DrawString(label, font1, PdfBrushes.PaleVioletRed, x, y);
}
Effective screenshot:

Full codes:
private void button1_Click(object sender, RoutedEventArgs e)
{
// Create a pdf document.
PdfDocument doc = new PdfDocument();
doc.PageSettings.Margins.All = 0;
PdfPageBase page = null;
PdfDocument original = new PdfDocument();
original.LoadFromFile("Test.pdf");
SetDocumentTemplate(doc, PdfPageSize.A4, original.PageSettings.Margins);
foreach (PdfPageBase origianlPage in original.Pages)
{
page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height));
origianlPage.CreateTemplate().Draw(page, 0, -(original.PageSettings.Margins.Top));
}
doc.SaveToFile("output.pdf");
System.Diagnostics.Process.Start("output.pdf");
}
private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
{
PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, margin.Top);
topSpace.Foreground = true;
doc.Template.Top = topSpace;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Trebuchet MS", 14f, System.Drawing.FontStyle.Italic));
String label = "This is a PDF text header";
SizeF size = font1.MeasureString(label);
float y = 0;
float x = 0;
topSpace.Graphics.DrawString(label, font1, PdfBrushes.PaleVioletRed, x, y);
}
A page border is a border that appears outside the margins on each page. Page borders are primarily for decoration so you can use any style, color, and line thickness you want. A good page border can make your page more appealing. In this section, we will demonstrate how to set up page borders in word using Spire.Doc for WPF.
Step 1: Initialize a new instance of Document class. Load the word document from the file.
Document document = new Document();
document.LoadFromFile("Emily.docx");
Step 2: Add page borders and set up the format of borders. In this instance, we set the style of border to ThinThickLargeGap and set the color to yellow green.
Section section = document.Sections[0]; section.PageSetup.Borders.BorderType = BorderStyle.ThinThickLargeGap; section.PageSetup.Borders.Color = Color.YellowGreen;
Step 3: Set up the space between the borders and the text.
section.PageSetup.Borders.Left.Space = 50; section.PageSetup.Borders.Right.Space = 50; section.PageSetup.Borders.Top.Space = 50; section.PageSetup.Borders.Bottom.Space = 50;
Step 4: Save the document and launch the file.
document.SaveToFile("Dickinson.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("Dickinson.docx");
Effective Screenshots:

Full codes:
using System.Drawing;
using System.Windows;
using Spire.Doc;
using Spire.Doc.Documents;
namespace Emily
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//Load Document
Document document = new Document();
document.LoadFromFile("Emily.docx");
Section section = document.Sections[0];
//Add Page Borders with Special Style and Color
section.PageSetup.Borders.BorderType = BorderStyle.ThinThickLargeGap;
section.PageSetup.Borders.Color = Color.YellowGreen;
//Space between Border and Text
section.PageSetup.Borders.Left.Space = 50;
section.PageSetup.Borders.Right.Space = 50;
section.PageSetup.Borders.Top.Space = 50;
section.PageSetup.Borders.Bottom.Space = 50;
//Save and Launch
document.SaveToFile("Dickinson.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("Dickinson.docx");
}
}
}
Imports System.Drawing
Imports System.Windows
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace Emily
'''
''' Interaction logic for MainWindow.xaml
'''
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
'Load Document
Dim document As New Document()
document.LoadFromFile("Emily.docx")
Dim section As Section = document.Sections(0)
'Add Page Borders with Special Style and Color
section.PageSetup.Borders.BorderType = BorderStyle.ThinThickLargeGap
section.PageSetup.Borders.Color = Color.YellowGreen
'Space between Border and Text
section.PageSetup.Borders.Left.Space = 50
section.PageSetup.Borders.Right.Space = 50
section.PageSetup.Borders.Top.Space = 50
section.PageSetup.Borders.Bottom.Space = 50
'Save and Launch
document.SaveToFile("Dickinson.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("Dickinson.docx")
End Sub
End Class
Header or footer are pieces of text or images that appear at the top or bottom of every document page. You can add any information you want to the header and footer areas such as page numbers, author's name, current date and company logo.
This article will demonstrate how to insert text header and footer for word document in WPF by using Spire.Doc for WPF.
Below are the effective screenshots after inserting header and footer:


At first, please download Spire.Doc and install it correctly, then add Spire.Doc.Wpf.dll and Spire.License.dll from the installation folder to your project as reference.
Then follow the detail steps below:
Use namespace:
using System.Windows; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing;
Insert Header
Step 1: Initialize a new instance of Document class and load the word document from file.
Document doc = new Document();
doc.LoadFromFile("Eiffel Tower.docx");
Step 2: Get its first section, then add a header paragraph for section one.
Section section = doc.Sections[0]; HeaderFooter header = section.HeadersFooters.Header; Paragraph paragraph = header.AddParagraph();
Step 3: Append text for header paragraph and set text format.
TextRange text = paragraph.AppendText("Eiffel Tower introduction");
text.CharacterFormat.FontName = "Cambria";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkGreen;
Step 4: Set Header Paragraph Format.
paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; paragraph.Format.Borders.Bottom.BorderType = BorderStyle.DashSmallGap; paragraph.Format.Borders.Bottom.Space = 0.05f; paragraph.Format.Borders.Bottom.Color = Color.DarkGray;
Insert Footer
Step 5: Add a Footer paragraph.
HeaderFooter footer = section.HeadersFooters.Footer; Paragraph sparagraph = footer.AddParagraph();
Step 6: Append text for footer paragraph and set text format.
TextRange stext = sparagraph.AppendText("the tallest structure in Paris");
stext.CharacterFormat.FontName = "Calibri";
stext.CharacterFormat.FontSize = 12;
stext.CharacterFormat.TextColor = Color.DarkGreen;
Step 7: Set Footer Paragrah Format.
sparagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; sparagraph.Format.Borders.Top.BorderType = BorderStyle.Hairline; sparagraph.Format.Borders.Top.Space = 0.15f; sparagraph.Format.Borders.Color = Color.DarkGray;
Step 8: Save and launch the file.
doc.SaveToFile("HeaderFooter.docx");
System.Diagnostics.Process.Start("HeaderFooter.docx");
Full codes:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Document doc = new Document();
doc.LoadFromFile("Eiffel Tower.docx");
Section section = doc.Sections[0];
HeaderFooter header = section.HeadersFooters.Header;
Paragraph paragraph = header.AddParagraph();
TextRange text = paragraph.AppendText("Eiffel Tower introduction");
text.CharacterFormat.FontName = "Cambria";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkGreen;
paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
paragraph.Format.Borders.Bottom.BorderType = BorderStyle.DashSmallGap;
paragraph.Format.Borders.Bottom.Space = 0.05f;
paragraph.Format.Borders.Bottom.Color = Color.DarkGray;
HeaderFooter footer = section.HeadersFooters.Footer;
Paragraph sparagraph = footer.AddParagraph();
TextRange stext = sparagraph.AppendText("the tallest structure in Paris");
stext.CharacterFormat.FontName = "Calibri";
stext.CharacterFormat.FontSize = 12;
stext.CharacterFormat.TextColor = Color.DarkGreen;
sparagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
sparagraph.Format.Borders.Top.BorderType = BorderStyle.Hairline;
sparagraph.Format.Borders.Top.Space = 0.15f;
sparagraph.Format.Borders.Color = Color.DarkGray;
doc.SaveToFile("HeaderFooter.docx");
System.Diagnostics.Process.Start("HeaderFooter.docx");
}
}
}
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim doc As New Document()
doc.LoadFromFile("Eiffel Tower.docx")
Dim section As Section = doc.Sections(0)
Dim header As HeaderFooter = section.HeadersFooters.Header
Dim paragraph As Paragraph = header.AddParagraph()
Dim text As TextRange = paragraph.AppendText("Eiffel Tower introduction")
text.CharacterFormat.FontName = "Cambria"
text.CharacterFormat.FontSize = 12
text.CharacterFormat.TextColor = Color.DarkGreen
paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right
paragraph.Format.Borders.Bottom.BorderType = BorderStyle.DashSmallGap
paragraph.Format.Borders.Bottom.Space = 0.05F
paragraph.Format.Borders.Bottom.Color = Color.DarkGray
Dim footer As HeaderFooter = section.HeadersFooters.Footer
Dim sparagraph As Paragraph = footer.AddParagraph()
Dim stext As TextRange = sparagraph.AppendText("the tallest structure in Paris")
stext.CharacterFormat.FontName = "Calibri"
stext.CharacterFormat.FontSize = 12
stext.CharacterFormat.TextColor = Color.DarkGreen
sparagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right
sparagraph.Format.Borders.Top.BorderType = BorderStyle.Hairline
sparagraph.Format.Borders.Top.Space = 0.15F
sparagraph.Format.Borders.Color = Color.DarkGray
doc.SaveToFile("HeaderFooter.docx")
System.Diagnostics.Process.Start("HeaderFooter.docx")
End Sub
Footnote is a note at the bottom of a page that gives more detailed information about something on the page. In this section, we will demonstrate how to add footnote in word using Spire.Doc for WPF.
First, create a new project by choosing WPF Application in Visual Studio, adding a button in the Main Window. Add Spire.Doc.Wpf.dll as reference to your project, and then double click the button to start.
Step 1: Initialize a new instance of Document class. Load the word document from the file.
Document doc = new Document();
doc.LoadFromFile("Oscar.docx");
Step 2: Select the section and paragraph which needs adding footnote. In this example, we choose the first section and the fourth paragraph.
Section sec = doc.Sections[0]; Paragraph paragraph = sec.Paragraphs[3];
Step 3: Add footnote by the method of paragraph.AppendFootnote() and then add the footnote contents by using footnote.TextBody.AddParagraph().AppendText(). At last, set the font style, size and color.
Footnote fn = paragraph.AppendFootnote(FootnoteType.Footnote);
TextRange text = fn.TextBody.AddParagraph().AppendText("Oscar Wilde (film), a 1960 biographical film about Oscar Wilde");
text.CharacterFormat.FontName = "Calibri";
text.CharacterFormat.FontSize = 11;
text.CharacterFormat.TextColor = Color.Chocolate;
Step 4: Set format of the marker.
fn.MarkerCharacterFormat.FontName = "Arial"; fn.MarkerCharacterFormat.FontSize = 14; fn.MarkerCharacterFormat.Bold = true; fn.MarkerCharacterFormat.TextColor = Color.Brown;
Step 5: Save the document and launch the file.
document.SaveToFile("FootNote.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("FootNote.docx");
Effective Screenshot:


Full codes:
using System.Drawing;
using System.Windows;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Add_Footnote_to_Word
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Document doc = new Document();
doc.LoadFromFile("Oscar.docx");
Section sec = doc.Sections[0];
Paragraph paragraph = sec.Paragraphs[3];
Footnote fn = paragraph.AppendFootnote(FootnoteType.Footnote);
TextRange text = fn.TextBody.AddParagraph().AppendText("Oscar Wilde (film), a 1960 biographical film about Oscar Wilde");
text.CharacterFormat.FontName = "Calibri";
text.CharacterFormat.FontSize = 11;
text.CharacterFormat.TextColor = Color.Chocolate;
fn.MarkerCharacterFormat.FontName = "Arial";
fn.MarkerCharacterFormat.FontSize = 14;
fn.MarkerCharacterFormat.Bold = true;
fn.MarkerCharacterFormat.TextColor = Color.Brown;
doc.SaveToFile("AddFootNote.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("AddFootNote.docx");
}
}
}
Imports System.Drawing
Imports System.Windows
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace Add_Footnote_to_Word
'''
''' Interaction logic for MainWindow.xaml
'''
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim doc As New Document()
doc.LoadFromFile("Oscar.docx")
Dim sec As Section = doc.Sections(0)
Dim paragraph As Paragraph = sec.Paragraphs(3)
Dim fn As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)
Dim text As TextRange = fn.TextBody.AddParagraph().AppendText("Oscar Wilde (film), a 1960 biographical film about Oscar Wilde")
text.CharacterFormat.FontName = "Calibri"
text.CharacterFormat.FontSize = 11
text.CharacterFormat.TextColor = Color.Chocolate
fn.MarkerCharacterFormat.FontName = "Arial"
fn.MarkerCharacterFormat.FontSize = 14
fn.MarkerCharacterFormat.Bold = True
fn.MarkerCharacterFormat.TextColor = Color.Brown
doc.SaveToFile("AddFootNote.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("AddFootNote.docx")
End Sub
End Class
End Namespace
Generally, a hyperlink is a picture or a piece of text which contains a web link that points to another object. The object can be a website, an email address and a file, etc. By clicking on the hyperlink, readers can access the target place quickly and conveniently.
This article demonstrates how to insert hyperlink in excel for WPF Applications by using Spire.XLS for WPF.
Below is the effective screenshot:

In this sample, we added two hyperlinks: one for cell A5, another for cell D13. Now, refer to the following detail steps:
Code snippets:
Use namespace:
using System.Windows; using Spire.Xls;
Step 1: Initialize a new instance of Workbook class and load the excel document from file, then get its first worksheet.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Vendors Information.xlsx");
Worksheet sheet = workbook.Worksheets[0];
Step 2: In the first worksheet, add hyperlink to cell A5, set its display text as the existing text of cell A5, next set type and address.
HyperLink Link = sheet.HyperLinks.Add(sheet.Range["A5"]); Link.TextToDisplay = sheet.Range["A5"].Text; Link.Type = HyperLinkType.Url; Link.Address = "https://en.wikipedia.org/wiki/Canada";
Step 3: Add a new hyperlink to cell D13 and set its display text, type and address.
HyperLink NewLink = sheet.HyperLinks.Add(sheet.Range["D13"]); NewLink.TextToDisplay = "https://www.google.com"; NewLink.Type = HyperLinkType.Url; NewLink.Address = "https://www.google.com";
Step 4: Save and launch the file.
workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("Hyperlink.xlsx");
Full codes:
private void button1_Click(object sender, RoutedEventArgs e)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("Vendors Information.xlsx");
Worksheet sheet = workbook.Worksheets[0];
HyperLink Link = sheet.HyperLinks.Add(sheet.Range["A5"]);
Link.TextToDisplay = sheet.Range["A5"].Text;
Link.Type = HyperLinkType.Url;
Link.Address = "https://en.wikipedia.org/wiki/Canada";
HyperLink NewLink = sheet.HyperLinks.Add(sheet.Range["D13"]);
NewLink.TextToDisplay = "https://www.google.com";
NewLink.Type = HyperLinkType.Url;
NewLink.Address = "https://www.google.com";
workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("Hyperlink.xlsx");
}
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim workbook As New Workbook()
workbook.LoadFromFile("Vendors Information.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim Link As HyperLink = sheet.HyperLinks.Add(sheet.Range("A5"))
Link.TextToDisplay = sheet.Range("A5").Text
Link.Type = HyperLinkType.Url
Link.Address = "https://en.wikipedia.org/wiki/Canada"
Dim NewLink As HyperLink = sheet.HyperLinks.Add(sheet.Range("D13"))
NewLink.TextToDisplay = "https://www.google.com"
NewLink.Type = HyperLinkType.Url
NewLink.Address = "https://www.google.com"
workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010)
System.Diagnostics.Process.Start("Hyperlink.xlsx")
End Sub