.NET (1322)
Children categories
Adding text into the PDF files is one of the most important requirements for developers. With the help of Spire.PDF, developer can draw transform text, alignment text and rotate text in PDF files easily. This tutorial will show you how to add underline text in C#.
By using the method canvas.drawstring offered by Spire.PDF, developers can set the position, font, brush and style for the adding texts. With the PdfFontStyle, developers can set the style to underline, bold, italic, regular and strikeout. Here comes to the code snippet of how to add underline text in PDF.
Step 1: Create a new PDF document.
PdfDocument pdf = new PdfDocument();
Step 2: Add a new page to the PDF file.
PdfPageBase page = pdf.Pages.Add();
Step 3: Create a true type font with size 20f, underline style.
PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);
Step 4: Create a blue brush.
PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
Step 5: Draw the text string at the specified location with the specified Brush and Font objects.
page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));
Step 6: Save the PDF file.
pdf.SaveToFile("Result.pdf", FileFormat.PDF);
Effective screenshot:

Full codes:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddUnderlinetext
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);
PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));
pdf.SaveToFile("Result.pdf", FileFormat.PDF);
}
}
}
Built-in table styles are predefined formatting options that can be quickly applied to any table, greatly enhancing its appearance and readability. As same as MS PowerPoint, Spire.Presentation provides such a feature to give your table a professional look by applying a certain built-in table style. This article presents how this purpose can be achieved using Spire.Presentation with C#, VB.NET.
As we can see from below picture, plain tale is not that attractive before applying any style.

Code Snippet for Applying Table Style:
Step 1: Create an instance of presentation and load the test file.
Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);
Step 2: Get the table from presentation slide.
ITable table = ppt.Slides[0].Shapes[1] as ITable;
Step 3: Choose one table style from TableStylePreset and apply it to selected table.
table.StylePreset = TableStylePreset.MediumStyle2Accent2;
Step 4: Save the file.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
Output:

Full Code:
using Spire.Presentation;
namespace Apply_Built_in_Style
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);
ITable table = ppt.Slides[0].Shapes[1] as ITable;
table.StylePreset = TableStylePreset.MediumStyle2Accent2;
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
}
}
}
Imports Spire.Presentation
Namespace Apply_Built_in_Style
Class Program
Private Shared Sub Main(args As String())
Dim ppt As New Presentation("test.pptx", FileFormat.Pptx2010)
Dim table As ITable = TryCast(ppt.Slides(0).Shapes(1), ITable)
table.StylePreset = TableStylePreset.MediumStyle2Accent2
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010)
End Sub
End Class
End Namespace

Auto filters in Excel are a powerful feature for sorting and analyzing data. However, once you’ve finished your data review or need to share the file in its original, unfiltered form, it’s often necessary to remove auto filters from Excel worksheets. If you’re building .NET applications, you can automate this task easily using Spire.XLS for .NET — whether you're removing filters from a single sheet or processing Excel files in batches.
In this article, you'll learn how to remove auto filters in Excel using Spire.XLS for .NET in C# programs.
Here’s what we will cover:
- Why Remove Auto Filters in Excel?
- How to Remove Auto Filters in Excel Using Spire.XLS
- Why Use Spire.XLS to Remove Filters?
- Frequently Asked Questions
Why Remove Auto Filters in Excel?
Removing auto filters in Excel can be essential for:
- Restoring full visibility of your data after filtering
- Preparing spreadsheets for export, printing, or presentation
- Sharing files without hidden or partial data views
In other words, removing filters in Excel files helps maintain data clarity, especially when passing documents to clients, teams, or reports.
How to Remove Auto Filters in Excel Using Spire.XLS
Setting Up Spire.XLS for .NET
Before getting started, install the Spire.XLS library via NuGet:
PM> Install-Package Spire.XLS
Or install the free version for lightweight Excel processing:
PM> Install-Package FreeSpire.XLS
You can also download Spire.XLS for .NET or Free Spire.XLS for .NET, and install the version you choose manually.
Key Methods and Properties Used
- Workbook.LoadFromFile() – Loads an existing Excel file into the Workbook object for processing.
- Workbook.Worksheets[] – Accesses a specific worksheet by index from the workbook.
- Worksheet.AutoFilters.Clear() – Removes all existing filter rules and makes all rows visible.
- Worksheet.AutoFilters.Range – Defines or updates the range of cells to which auto filters are applied.
- Workbook.SaveToFile() – Saves the modified workbook as a new Excel file.
C# Code Example: Remove All AutoFilters in Excel
Here’s a complete example of how to remove all auto-filters in Excel using C# and Spire.XLS:
- C#
using Spire.Xls;
// Create a Workbook instance
Workbook workbook = new Workbook();
// Load an Excel workbook
workbook.LoadFromFile("Sample.xlsx");
// Get a worksheet
Worksheet sheet = workbook.Worksheets[0];
// Remove auto-filters
sheet.AutoFilters.Clear();
// Save the workbook
workbook.SaveToFile("output/RemoveExcelFilter.xlsx");
workbook.Dispose();
Excel Worksheet Before and After Removing All Auto Filters

Removing a Specific Filter Column in an Excel Worksheet
In Excel, auto filters are applied to a continuous range of columns. This means you can’t directly remove the filter from just one column if it's part of a larger filter range. If you need to exclude a specific column from filtering, you’ll have to reset the filter range in Excel worksheets to adjacent columns.
Here’s how you can do it using Spire.XLS:
- C#
using Spire.Xls;
// Create a Workbook instance
Workbook workbook = new Workbook();
// Load an Excel workbook
workbook.LoadFromFile("Sample.xlsx");
// Get a worksheet
Worksheet sheet = workbook.Worksheets[0];
// Remove the current filters to show all data (to avoid missing data)
sheet.AutoFilters.Clear();
// Reset the filter range
sheet.AutoFilters.Range = sheet.Range[1, 3, 5, 5];
// Save the workbook
workbook.SaveToFile("output/ResetExcelFilter.xlsx");
workbook.Dispose();
Note: Before resetting the filter range, make sure to remove any existing auto filters. Skipping this step can result in hidden (filtered-out) rows being excluded from the new range, potentially causing data to be lost or missed.
Excel Worksheet Before and After Removing a Specific Filter Column

Why Use Spire.XLS to Remove Filters?
- Fast & efficient: No need to open Excel files manually.
- Easy to integrate: Compatible with .NET Framework and .NET Core.
- No dependencies: Does not require Microsoft Office.
- Production-ready: Great for batch jobs and enterprise systems.
See Also: How to Add, Update, and Remove Excel Slicers in C#
Conclusion
Removing auto filters in Excel with Spire.XLS for .NET is quick and simple. Whether you're processing reports or resetting spreadsheets for clean data presentation, you can automate it easily using C#.
Frequently Asked Questions
- Q: How do you remove auto filters in Excel using C#?
Use the AutoFilters.Clear() method from Spire.XLS. It removes all filters from the specified worksheet in just one line of code.
- Q: What’s the easiest way to remove auto filters on Excel programmatically?
Using Spire.XLS for .NET, you can remove filters with a few lines of C# without opening Excel. It's fast, lightweight, and reliable.
- Q: Can I remove only specific filters instead of all of them?
In Excel (and Spire.XLS), auto filters must be applied to a continuous block of columns. You can’t directly remove a filter from just one column in the middle of a filtered range. To remove a specific filter, you need to clear all filters first using Worksheet.AutoFilters.Clear(), then reset the filter range using Worksheet.AutoFilters.Range to exclude the unwanted column.
- Q: Is there a free version of Spire.XLS for .NET?
Yes! We offer a free version – Free Spire.XLS for .NET, which is completely free to use and does not add watermarks to output files. It’s ideal for lightweight Excel processing.
If you want to evaluate the full feature set without any limitations, you can request a temporary license.
This article has demonstrated how to create a Windows Forms Application to open and close Word file using Spire.DocViewer. Now, we are adding a print button to Form1 to fulfill the print feature for this Word document viewer.
Detailed Steps
Step 1: Add another button to Form1, and set the following properties for it in the Properties Window:
- Name: btnPrint
- DisplayStyle: Image
- Image: Print.Properties.Resources.Print
Step 2: Double click the button to write code. In this button code, we firstly instantiate an object of System.Windows.Forms.PrintDialog and set some of its relative properties. Call ShowDialog method to make the print dialog visible.
private void btnPrint_Click(object sender, EventArgs e)
{
//Show a Print Dialog
PrintDialog dialog = new PrintDialog();
dialog.AllowCurrentPage = true;
dialog.AllowSomePages = true;
dialog.UseEXDialog = true;
DialogResult result = dialog.ShowDialog();
//...
}
Step 3: Set print parameters of DocDocumentViewer.PrintDialog and print the document.
//...
if (result == DialogResult.OK)
{
try
{
//Set print parameters.
this.docDocumentViewer1.PrintDialog = dialog;
//Gets the PrintDocument.
dialog.Document = docDocumentViewer1.PrintDocument;
dialog.Document.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Run the program, open an existing Word file and click 'Print' button, you'll get a dialog as below:

Auto Filter is the most convenient way to select the data we want from a large amount of the data in an excel data table. With the help of Spire.XLS for .NET, developers can use the method ListObjects to filter the data and format it as a table. This article will focus on show you how to add table with filter in Excel.
Step 1: Create an excel document and load the Excel from file:
Workbook workbook = new Workbook();
workbook.LoadFromFile("DataTable.xlsx");
Step 2: Gets the first worksheet in the Excel file
Worksheet sheet = workbook.Worksheets[0];
Step 3: Create a List Object named in Table
sheet.ListObjects.Create("Table", sheet.Range[1, 1, sheet.LastRow, sheet.LastColumn]);
Step 4: Set the BuiltInTableStyle for List object.
sheet.ListObjects[0].BuiltInTableStyle = TableBuiltInStyles.TableStyleLight9;
Step 5: Save the document to file.
workbook.SaveToFile("Filter.xlsx", ExcelVersion.Version2010);
Effective screenshot after the date has been auto filtered:

Full codes:
namespace Excelfilter
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("DataTable.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.ListObjects.Create("Table", sheet.Range[1, 1, sheet.LastRow, sheet.LastColumn]);
sheet.ListObjects[0].BuiltInTableStyle = TableBuiltInStyles.TableStyleLight9;
workbook.SaveToFile("Filter.xlsx", ExcelVersion.Version2010);
}
}
}
This article introduces how to export Word file pages as png images in Windows Forms Application using Spire.DocViewer. Let’s see detailed steps.
First, download Spire.DocViewer, add DocViewer Control to VS Toolbox.

Then create a Windows Forms Application, design your Form1 as below.
- Add 'Open Document' button to open an existing Word file.
- Add two check boxes and two text boxes, which are designed for choosing a range of pages to do the conversion.
- Add 'Save to Image' button to save selected pages as images.
- Drag 'DocDocumentViewer Control' into Form1, which is used to display Word document.

Code Snippet:
Step 1: Create an OpenFileDialog to select the correct file type that you want to load. If you try to open with another file type except .doc and .docx, error message 'Cannot detect current file type' will appear.
private void btnOpen_Click(object sender, EventArgs e)
{
//Open a Doc Document
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter="Word97-2003 files(*.doc)|*.doc|Word2007-2010 files (*.docx)|*.docx|All files (*.*)|*.*";
dialog.Title="Select a DOC file";
dialog.Multiselect=false;
dialog.InitialDirectory=System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data");
DialogResult result = dialog.ShowDialog();
if (result==DialogResult.OK)
{
try
{
// Load doc document from file.
this.docDocumentViewer1.LoadFromFile(dialog.FileName);
this.textBox2.Text = this.docDocumentViewer1.PageCount.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Step 2: The code behind 'Save to Image' button enables users to export the specified pages (from textbox1 to textBox2) as Bitmapsource, then convert Bitmapsource to images.
private void btnSaveImage_Click(object sender, EventArgs e)
{
this.Enabled = false;
bitMap.Clear();
try
{
if (ckbFrom.Checked && ckbTo.Checked)
{
try
{
int startIndex = 0;
int.TryParse(textBox1.Text, out startIndex);
m_CurrentPageNum = startIndex;
int endIndex = 0;
int.TryParse(textBox2.Text, out endIndex);
// Exports the specified pages as Images
Image[] bitmapsource = this.docDocumentViewer1.SaveImage((ushort)(startIndex), (ushort)(endIndex));
SaveImageToFile(bitmapsource);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (ckbFrom.Checked && !ckbTo.Checked)
{
try
{
int currepageIndex = 0;
int.TryParse(textBox1.Text, out currepageIndex);
m_CurrentPageNum = currepageIndex;
//Saves the specified page as Image
Image bitmapsource = this.docDocumentViewer1.SaveImage((ushort)(currepageIndex));
SaveImageToFile(new Image[] { bitmapsource });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch { };
this.Enabled = true;
}
Step 3: In step 2, SaveImageToFile() has been invoked. This part creates two customized methods SaveImageToFile() and WriteImageFile(), which is meant to save Bitmapsource as png images with the page index as its file name.
private void SaveImageToFile(Image[] bitmpaSource)
{
int startIndex = 1;
int.TryParse(textBox1.Text, out startIndex);
foreach (Image bitmap in bitmpaSource)
{
WriteImageFile(bitmap, startIndex);
startIndex++;
}
}
// BitmapSource Write to File
private void WriteImageFile(Image bitMapImg, int currentPageIndex)
{
try
{
if (bitMapImg != null)
{
string FullfileName = currentPageIndex.ToString() + ".png";
bitMapImg.Save(FullfileName, System.Drawing.Imaging.ImageFormat.Png);
bitMap.Add(FullfileName, bitMapImg);
}
}
catch (Exception ex)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine(ex.Message + ex.Source);
#endif
}
}
Debug the code, you'll get a Windows application as designed. Here, I open a sample Word file and select page 1 to page 11, selected pages will be saved as images in bin folder by clicking 'Save to Image'.

This article presents how to create a Windows Forms Application to open a Word file and convert it to PDF format using Spire.DocViewer. In fact, conversion from Word to HTML, RTF, DOC, DOCX are also supported with this DocViewer control. You can try almost the same way demonstrated in the following section to convert Word to any other format.
First of all, download Spire.DocViewer, add DocViewer Control to VS Toolbox.

Then create a Windows Forms application, design your Form1 as below.
- Add 'Open' button to open a file from existing Word document.
- Add 'Close' button to shut down the open file.
- Add 'ToPDF' button to save Word file as PDF format.
- Drag 'DocDocumentViewer Control' into Form1, which is used to display Word document.

Code Snippet:
Step 1: Initialize components in Form1.
public Form1()
{
InitializeComponent();
}
Step 2: Create an OpenFileDialog to select the correct file type that we want to load, otherwise error message 'Cannot detect current file type' will appear.
private void bntOpen_Click(object sender, EventArgs e)
{
//Open a doc document
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Word97-2003 files(*.doc)|*.doc|Word2007-2010 files (*.docx)|*.docx|All files (*.*)|*.*";
dialog.Title = "Select a DOC file";
dialog.Multiselect = false;
dialog.InitialDirectory = System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data");
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
try
{
this.docDocumentViewer1.LoadFromFile(dialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Step 3: In the 'ToPDF' button click event, create a SaveFileDialog, set filter as PDF type, then call DocDocumentViewer.SaveAs() method to save Word as PDF with customized file name.
private void btnSaveToPdf_Click(object sender, EventArgs e)
{
SaveFileDialog savefile = new SaveFileDialog();
savefile.Filter = "Pdf Document(*.pdf)|*.pdf";
savefile.Title = "Save";
DialogResult result = savefile.ShowDialog();
if (result == DialogResult.OK)
{
try
{
//Save PDF documetns
this.docDocumentViewer1.SaveAs(savefile.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Step 4: Close the open file.
private void btnClose_Click(object sender, EventArgs e)
{
//Close current doc document.
this.docDocumentViewer1.CloseDocument();
}
After debugging the code, I opened a sample Word file. The save dialog box will pop up by clicking 'ToPDF' button.

This article presents how to create a Windows Forms application to open and close your Word files using Spire.DocViewer component. Detailed steps would be as follows:
First of all, download Spire.DocViewer, add DocViewer Control to VS Toolbox.

Then create a Windows Forms application, design your Form1 as below.
- Add 'Open from file' button to open a file from existing Word document.
- Add 'Open from stream' button to load a Word file from steam.
- Add 'Close' button to shut down the open file.
- Drag 'DocDocumentViewer Control' into Form1, which is used to display Word document.

Code Snippet:
Step 1: Initialize components in Form1.
System.IO.FileStream stream;
public Form1()
{
InitializeComponent();
}
Step 2: Create an OpenFileDialog to select the correct file type that we want to load, otherwise error message 'Cannot detect current file type' will occur.
private void btnOpen_Click(object sender, EventArgs e)
{
//open a DOC document
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Word97-2003 files(*.doc)|*.doc|Word2007-2010 files (*.docx)|*.docx|All files (*.*)|*.*";
dialog.Title = "Select a DOC file";
dialog.Multiselect = false;
dialog.InitialDirectory = System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data");
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
try
{
//Load DOC document from file.
this.docDocumentViewer1.LoadFromFile(dialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Step 3: This button code enables users to open Word files from a stream in Xml or Microsoft Word format.
private void btnOpenStream_Click(object sender, EventArgs e)
{
//open a doc document
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Word97-2003 files(*.doc)|*.doc|Word2007-2010 files (*.docx)|*.docx|All files (*.*)|*.*";
dialog.Title = "Select a DOC file";
dialog.Multiselect = false;
dialog.InitialDirectory = System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data");
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
try
{
string docFile = dialog.FileName;
stream = new System.IO.FileStream(docFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
if (stream != null)
{
//Load doc document from stream.
this.docDocumentViewer1.LoadFromStream(stream, Spire.Doc.FileFormat.Auto);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Step 4: Close the open file.
private void btnClose_Click(object sender, EventArgs e)
{
//Close current doc document.
this.docDocumentViewer1.CloseDocument();
}
After running the code, I opened a test file with this Windows application. Here is the screenshot of effect:

Adding page numbers to your Word documents can enhance their organization and readability. Page numbers provide a convenient reference point for readers and make it easier to navigate through lengthy documents. Whether you're working on a report, thesis, or any other document, incorporating page numbers is a simple yet effective way to improve its overall structure and accessibility.
In this article, you will learn how to add page numbers to a Word document in C# by using the Spire.Doc for .NET library.
- Add Page Numbers to a Word Document
- Add Page Numbers to a Specific Section in a Word Document
- Add Different Page Numbers to Different Sections in a Word Document
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Add Page Numbers to a Word Document in C#
To achieve the dynamic addition of page numbers to a Word document, Spire.Doc for .NET offers a range of fields, including FieldPage, FieldNumPages, and FieldSectionPages. These fields act as placeholders for the current page number, total page count, and section page count, allowing you to customize and automate the display of page numbers in your document.
To incorporate these placeholders (usually in the header or footer section) within your Word document, you can utilize the Paragraph.AppendField() method.
The following steps outline how to add a FieldPage field and a FieldNumPages field in the footer, resulting in the display of "X/Y" format in the document.
- Create a Document object.
- Load a Word document from a specified file path.
- Get the first section using Document.Sections[index] property
- Get the footer of the first section using Section.HeadersFooters.Footer property.
- Add a paragraph to the footer using HeaderFooter.AddParagraph() method.
- Insert a FieldPage field, a FieldNumPages field and a "/" to the paragraph using Paragraph.AppendField() and Parargph.AppendText() methods.
- Save the document to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace AddPageNumbersToDocument
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document document = new Document();
// Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Privacy Policy.docx");
// Get the first section
Section section = document.Sections[0];
// Get the footer of the section
HeaderFooter footer = section.HeadersFooters.Footer;
// Add "page number / page count" to the footer
Paragraph footerParagraph = footer.AddParagraph();
footerParagraph.AppendField("page number", FieldType.FieldPage);
footerParagraph.AppendText(" / ");
footerParagraph.AppendField("page count", FieldType.FieldNumPages);
footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
// Apply formatting to the page number
ParagraphStyle style = new ParagraphStyle(document);
style.CharacterFormat.Bold = true;
style.CharacterFormat.FontName = "Times New Roman";
style.CharacterFormat.FontSize = 18;
style.CharacterFormat.TextColor = Color.Red;
document.Styles.Add(style);
footerParagraph.ApplyStyle(style);
// Save the document
document.SaveToFile("AddPageNumbersToDocument.docx");
// Dispose resources
document.Dispose();
}
}
}

Add Page Numbers to a Specific Section in a Word Document in C#
By default, page numbers in the footer of a section are automatically linked to the previous section, ensuring a continuous display. However, if you wish to add page numbers to a specific section only, you need to unlink the subsequent section from the previous section and remove the content of the footers in the subsequent sections.
The following are the steps to add page numbers to a specific section in a Word document using Spire.Doc for .NET.
- Create a Document object.
- Load a Word document from a specified file path.
- Get a specific section using Document.Sections[index] property
- Get the footer of the section using Section.HeadersFooters.Footer property.
- Restart page numbering from 1 by setting Section.PageSetup.RestartPageNumbering property to true and Section.PageSetup.PageStartingNumber property to 1.
- Insert a FieldPage field, a FieldSectionPages field and a "/" to the footer using Paragraph.AppendField() and Parargph.AppendText() methods.
- Disable "Link to previous" by setting HeadersFooters.Footer.LinkToPrevious propety to false.
- Delete the content of the footers in the subsequent sections
- Save the document to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace AddPageNumbersToSpecificSection
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document document = new Document();
// Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Privacy Policy.docx");
// Get a specific section
int sectionIndex = 1;
Section section = document.Sections[sectionIndex];
// Restart page numbering from 1
section.PageSetup.RestartPageNumbering = true;
section.PageSetup.PageStartingNumber = 1;
// Get the footer of the section
HeaderFooter footer = section.HeadersFooters.Footer;
// Add "page number / page count" to the footer
Paragraph footerParagraph = footer.AddParagraph();
footerParagraph.AppendField("page number", FieldType.FieldPage);
footerParagraph.AppendText(" / ");
footerParagraph.AppendField("page count", FieldType.FieldSectionPages);
footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
// Apply formatting to the page number
ParagraphStyle style = new ParagraphStyle(document);
style.CharacterFormat.Bold = true;
style.CharacterFormat.FontName = "Times New Roman";
style.CharacterFormat.FontSize = 18;
style.CharacterFormat.TextColor = Color.Red;
document.Styles.Add(style);
footerParagraph.ApplyStyle(style);
// Disable "Link to previous" in the subsequent section
document.Sections[sectionIndex + 1].HeadersFooters.Footer.LinkToPrevious = false;
// Delete the content of the footers in the subsequent sections
for (int i = sectionIndex + 1; i < document.Sections.Count; i++)
{
document.Sections[i].HeadersFooters.Footer.ChildObjects.Clear();
document.Sections[i].HeadersFooters.Footer.AddParagraph();
}
// Save the document
document.SaveToFile("AddPageNumbersToSection.docx");
// Dispose resources
document.Dispose();
}
}
}

Add Different Page Numbers to Different Sections in a Word Document in C#
To ensure that different sections have distinct page numbers, you need to get each section in the document, add page numbers to them separately, and restart page numbering from 1 at the beginning of each section.
The following are detailed steps.
- Create a Document object.
- Load a Word document from a specified file path.
- Iterate through the sections in the document.
- Get a specific section using Document.Sections[index] property
- Get the footer of the section using Section.HeadersFooters.Footer property.
- Restart page numbering from 1 by setting Section.PageSetup.RestartPageNumbering property to true and Section.PageSetup.PageStartingNumber property to 1.
- Insert a FieldPage field, a FieldSectionPages field and a "/" to the footer using Paragraph.AppendField() and Parargph.AppendText() methods.
- Save the document to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace AddDifferentPageNumbersToDifferentSections
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document document = new Document();
// Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Privacy Policy.docx");
// Iterate through the sections in the document
for (int i = 0; i < document.Sections.Count; i++)
{
// Get a specific section
Section section = document.Sections[i];
// Restart page numbering from 1
section.PageSetup.RestartPageNumbering = true;
section.PageSetup.PageStartingNumber = 1;
// Get the footer of the section
HeaderFooter footer = section.HeadersFooters.Footer;
// Add "page number / page count" to the footer
Paragraph footerParagraph = footer.AddParagraph();
footerParagraph.AppendField("page number", FieldType.FieldPage);
footerParagraph.AppendText(" / ");
footerParagraph.AppendField("page count", FieldType.FieldSectionPages);
footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
// Apply formatting to the page number
ParagraphStyle style = new ParagraphStyle(document);
style.CharacterFormat.Bold = true;
style.CharacterFormat.FontName = "Times New Roman";
style.CharacterFormat.FontSize = 18;
style.CharacterFormat.TextColor = Color.Red;
document.Styles.Add(style);
footerParagraph.ApplyStyle(style);
}
// Save the document
document.SaveToFile("AddDifferentPageNumbersToSections.docx");
// Dispose resources
document.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
An Excel chart is a graphical representation of numbers, which visualizes your data in selected data table. Sometimes, we create a chart with MS Excel, but we don't really want to share the whole Excel file except for the chart. In such a case, we can export charts as image files for easy sharing. In the following section, you will learn how to save your Excel chart as an image in C# and VB.NET via Spire.XLS.
In the test file, I have created four different type of charts based on a same data table. Then, let’s see how each chart can be saved as an image with code.
Test File:

Code Snippet:
Step 1: Create a new workbook and load the test file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("chart.xlsx", ExcelVersion.Version2010);
Step 2: Get the worksheet that contains the chart from workbook.
Worksheet sheet=workbook.Worksheets[0];
Step 3: Initialize a new instance of image array to store the Bitmap images which are converted from charts.
Image[] imgs = workbook.SaveChartAsImage(sheet);
Step 4: Traverse every item in image array and save them to specified image format.
for (int i = 0; i < imgs.Length; i++)
{
imgs[i].Save(string.Format("img-{0}.png", i), ImageFormat.Png);
}
Output:
Charts have been saved as images in bin folder.

The second chart looks like:

Full Code:
using Spire.Xls;
using System.Drawing;
using System.Drawing.Imaging;
namespace SaveExcelCharts
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("chart.xlsx", ExcelVersion.Version2010);
Worksheet sheet = workbook.Worksheets[0];
Image[] imgs = workbook.SaveChartAsImage(sheet);
for (int i = 0; i < imgs.Length; i++)
{
imgs[i].Save(string.Format("img-{0}.png", i), ImageFormat.Png);
}
}
}
}
Imports Spire.Xls
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace SaveExcelCharts
Class Program
Private Shared Sub Main(args As String())
Dim workbook As New Workbook()
workbook.LoadFromFile("chart.xlsx", ExcelVersion.Version2010)
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim imgs As Image() = workbook.SaveChartAsImage(sheet)
For i As Integer = 0 To imgs.Length - 1
imgs(i).Save(String.Format("img-{0}.png", i), ImageFormat.Png)
Next
End Sub
End Class
End Namespace