A ChartSheet represents a chart sheet. It is a worksheet that contains only a chart. This article will demonstrate how to convert a chart sheet to SVG stream by using Spire.XLS.

Firstly, view the sample Excel worksheets with two chart sheets.

How to save Excel chart sheet to SVG in C#

Convert all the chart sheets to SVG stream:

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //call ToSVGStream(Stream stream) method to save each chart sheet to SVG stream 
            for (int i = 0; i < workbook.Chartsheets.Count; i++)
            {
                FileStream fs = new FileStream(string.Format("chartsheet-{0}.svg", i), FileMode.Create);
                workbook.Chartsheets[i].ToSVGStream(fs);
                fs.Flush();
                fs.Close();
            }


        }
    }
}

Effective screenshot of the two chart sheets to SVG.

How to save Excel chart sheet to SVG in C#

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //get the second chartsheet by name
            ChartSheet cs = workbook.GetChartSheetByName("Chart2");

            //save to SVG stream
            FileStream fs = new FileStream(string.Format("chart2.svg"), FileMode.Create);
            cs.ToSVGStream(fs);
            fs.Flush();
            fs.Close();


        }
    }
}

How to save Excel chart sheet to SVG in C#

Alternative text (alt text) can help people with screen readers understand the content of our table. This article is going to demonstrate how to add or get the alternative text of a table in a word document using Spire.Doc.

In Spire.Doc, we can set or get the alternative text of a table using the Table.Title and Table.TableDescription properties. The following example shows how to add alternative text to a table.

Detail steps:

Step 1: Instantiate a Document object and load a word document.

Document doc = new Document();
doc.LoadFromFile("Input.docx");

Step 2: Get the first section.

Section section = doc.Sections[0];

Step 3: Get the first table in the section.

Table table = section.Tables[0] as Table;

Step 4: Add alt text to the table.

//Add title
table.Title = "Table 1";
//Add description
table.TableDescription = "Description Text";

Step 5: Save the document.

doc.SaveToFile("output.docx", FileFormat.Docx2013);

Screenshot:

Add/Get Alternative Text of Table in Word in C#

Full code:

using Spire.Doc;

namespace Add_Alt_Text_To_Word_Table
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Document object
            Document doc = new Document();
            //Load a word document
            doc.LoadFromFile("Input.docx");

            //Get the first section
            Section section = doc.Sections[0];

            //Get the first table in the section
            Table table = section.Tables[0] as Table;
 
            //Add alt text

            //Add tile
            table.Title = "Table 1";
            //Add description
            table.TableDescription = "Description Text";

            //Save the document
            doc.SaveToFile("output.docx", FileFormat.Docx2013);            
        }
    }
}

We have demonstrated how to use Spire.Presentation to add and get speaker notes in presentation slides. This article will show how to remove the speaker notes in presentation slides in C#.

Firstly, view the sample document contains the speaker notes.

How to remove speaker notes from a presentation slide in C#

Step 1: Create a presentation document and load the document from the file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Step 2: Get the first slide from the sample document.

ISlide slide = ppt.Slides[0];

Step 3: Remove the first speak notes:

slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1);

Remove all the speak notes from the first slide:

slide.NotesSlide.NotesTextFrame.Paragraphs.Clear();

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx",FileFormat.Pptx2013);

Effective screenshot of removing the first note:

How to remove speaker notes from a presentation slide in C#

Effective screenshot of removing all the notes:

How to remove speaker notes from a presentation slide in C#

Full codes:

Remove the first note in presentation slide:

using Spire.Presentation;
namespace RemoveSpeakerNotes
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

            ISlide slide = ppt.Slides[0];

            slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1);
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);

        }

    }
}

Clear all notes in presentation slide:

Imports Spire.Presentation
Namespace RemoveSpeakerNotes

	Class Program

		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation()
			ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013)

			Dim slide As ISlide = ppt.Slides(0)

			slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1)
			ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013)

		End Sub

	End Class
End Namespace

Split Table Cells in PowerPoint in C#

2018-09-26 08:02:37 Written by Koohji

This article is going to demonstrate how to split a specific table cell in PowerPoint using Spire.Presentation.

The original table:

Split Table Cells in PowerPoint in C#

Detail steps:

Step 1: Instantiate a Presentation object and load the PowerPoint file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Input.pptx");

Step 2: Get the first slide.

ISlide slide = ppt.Slides[0];

Step 3: Get the table on the slide.

ITable table = slide.Shapes[0] as ITable;

Step 4: Split the cell [1, 2] into 3 rows and 2 columns.

table[1, 2].Split(3, 2);

Step 5: Save the file.

ppt.SaveToFile("Split.pptx", FileFormat.Pptx2013);

Screenshot after splitting:

Split Table Cells in PowerPoint in C#

Full code:

using Spire.Presentation;

namespace Split_Table_Cells_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Presentation object
            Presentation ppt = new Presentation();
            //Load the PowerPoint file
            ppt.LoadFromFile("Input.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Get the table
            ITable table = slide.Shapes[0] as ITable;

            //Split cell [1, 2] into 3 rows and 2 columns
            table[1, 2].Split(3, 2);

            //Save the file
            ppt.SaveToFile("Split.pptx", FileFormat.Pptx2013);
        }
    }
}

Charts are commonly used in Microsoft Excel files to visualize numeric data. In some cases, you may need to save the charts in an Excel file as images in order to use them in other programs or other files such as PDFs and PowerPoint presentations. In this article, we will demonstrate how to convert charts in Excel to images in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Convert a Specific Chart in an Excel Worksheet to Image in C# and VB.NET

Spire.XLS provides the Workbook.SaveChartAsImage(Worksheet worksheet, int chartIndex) method which enables you to convert a specific chart in a worksheet as image. The following are the detailed steps:

  • Initialize an instance of the Workbook class.
  • Load a sample Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet by its index through Workbook.Worksheets[int worksheetIndex] property.
  • Save a specific chart in the worksheet as image using Workbook.SaveChartAsImage(Worksheet worksheet, int chartIndex) method.
  • Save the image to a PNG file.
  • C#
  • VB.NET
using Spire.Xls;
using System.Drawing;
using System.Drawing.Imaging;

namespace ConvertAExcelChartToImage
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load a sample Excel file
            workbook.LoadFromFile("Charts.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Save the first chart in the first worksheet as image
            Image image = workbook.SaveChartAsImage(sheet, 0);
            //Save the image to .png file
            image.Save(@"output\chart.png", ImageFormat.Png);
        }
    }
}

C#/VB.NET: Convert Charts in Excel to Images

Convert All Charts in an Excel Worksheet to Images in C# and VB.NET

To convert all charts in an Excel worksheet to images, you can use the Workbook.SaveChartAsImage(Worksheet worksheet) method. The following are the detailed steps:

  • Initialize an instance of the Workbook class.
  • Load a sample Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet by its index through Workbook.Worksheets[int worksheetIndex] property.
  • Save all charts in the worksheet as images using Workbook.SaveChartAsImage(Worksheet worksheet) method.
  • Save the images to PNG files.
  • C#
  • VB.NET
using Spire.Xls;
using System.Drawing;
using System.Drawing.Imaging;

namespace ConvertAllExcelChartsToImages
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load a sample Excel file
            workbook.LoadFromFile("Charts.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Save charts in the first worksheet as images
            Image[] imgs = workbook.SaveChartAsImage(sheet);

            //Save the images to png files
            for (int i = 0; i < imgs.Length; i++)
            {
                imgs[i].Save(string.Format(@"output\chart-{0}.png", i), ImageFormat.Png);
            }
        }
    }
}

C#/VB.NET: Convert Charts in Excel to Images

Convert a Chart Sheet to Image in Excel in C# and VB.NET

You can use the Workbook.SaveChartAsImage(ChartSheet chartSheet) method to convert a chart sheet in Excel to image. The following are the detailed steps:

  • Initialize an instance of the Workbook class.
  • Load a sample Excel file using Workbook.LoadFromFile() method.
  • Get a specific chart sheet by its index through Workbook.Chartsheets[int chartSheetIndex] property.
  • Save the chart sheet as image using Workbook.SaveChartAsImage(ChartSheet chartSheet) method.
  • Save the image to .png file.
  • C#
  • VB.NET
using Spire.Xls;
using System.Drawing;
using System.Drawing.Imaging;

namespace ConvertExcelChartSheetToImage
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load a sample Excel file
            workbook.LoadFromFile("ChartSheet.xlsx");

            //Get the first chart sheet
            ChartSheet chartSheet = workbook.Chartsheets[0];

            //Save the first chart sheet as image
            Image image = workbook.SaveChartAsImage(chartSheet);
            //Save the image to .png file
            image.Save(@"output\chartSheet.png", ImageFormat.Png);            
        }
    }
}

C#/VB.NET: Convert Charts in Excel to Images

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.

This article demonstrates how to replace an existing image with a new image in a PowerPoint document using Spire.Presentation.

The original image:

Replace Image with New Image in PowerPoint in C#

Detail steps:

Step 1: Instantiate a Presentation object and load the PowerPoint file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Input.pptx");

Step 2: Get the first slide.

ISlide slide = ppt.Slides[0];

Step 3: Append a new image to replace an existing image.

IImageData image = ppt.Images.Append(Image.FromFile("timg.jpg"));

Step 4: Replace the image which title is "image1" with the new image.

foreach (IShape shape in slide.Shapes)
{
    if (shape is SlidePicture)
    {
        if (shape.AlternativeTitle == "image1")
        {
            (shape as SlidePicture).PictureFill.Picture.EmbedImage = image;
        }
    }
}

Step 5: Save the file.

ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);

Screenshot after replacing image:

Replace Image with New Image in PowerPoint in C#

Full code:

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace ReplaceImage
{

    class Program
    {

        static void Main(string[] args)
        {
            {
                Presentation ppt = new Presentation();
                ppt.LoadFromFile("Input.pptx");

                ISlide slide = ppt.Slides[0];

                IImageData image = ppt.Images.Append(Image.FromFile("timg.jpg"));

                foreach (IShape shape in slide.Shapes)
                {
                    if (shape is SlidePicture)
                    {
                        if (shape.AlternativeTitle == "image1")
                        {
                            (shape as SlidePicture).PictureFill.Picture.EmbedImage = image;
                        }
                    }
                }

                ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);



            }
        }

    }
}

This article demonstrates how to detect the used themes in a PowerPoint document using Spire.Presentation.

Detail steps:

Step 1: Instantiate a Presentation object and load the PowerPoint document.

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"Sample.pptx");

Step 2: Get the theme name of each slide in the document.

StringBuilder sb = new StringBuilder();
string themeName = null;

foreach (ISlide slide in ppt.Slides)
{
    themeName = slide.Theme.Name;
    sb.AppendLine(themeName);
}

Step 3: Save to a .txt file.

File.WriteAllText("themeName.txt", sb.ToString());

Output:

Detect the used themes in PowerPoint in C#

Full code:

using Spire.Presentation;
using System.IO;
using System.Text;
namespace DetectThemes 
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Presentation object
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile(@"Sample.pptx");

            StringBuilder sb = new StringBuilder();
            string themeName = null;

            //Get the theme name of each slide in the document
            foreach (ISlide slide in ppt.Slides)
            {
                themeName = slide.Theme.Name;
                sb.AppendLine(themeName);
            }

            //Save to a .txt file
            File.WriteAllText("themeName.txt", sb.ToString());

            }
        }
    }

In Excel, cells can be filtered based on the cell color. This article is going to show you how to filter rows by cell color using Spire.XLS.

The example Excel file:

Filter cells by cell color in Excel in C#

Detail steps:

Step 1: Instantiate a Workbook object and load the Excel file.

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

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Add a color filter to filter cells based on cell color.

//Create an auto filter in the sheet and specify the range to be filterd
sheet.AutoFilters.Range = sheet.Range["A1:A9"];
//Get the coloumn to be filterd
FilterColumn filtercolumn = (FilterColumn)sheet.AutoFilters[0];
//Add a color filter to filter the column based on cell color
sheet.AutoFilters.AddFillColorFilter(filtercolumn, Color.Red);    

Step 4: Filter the data.

sheet.AutoFilters.Filter();

Step 5: Save the file.

workbook.SaveToFile("ColorFilter.xlsx", ExcelVersion.Version2013);

Screenshot:

Filter cells by cell color in Excel in C#

Full code:

using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.AutoFilter;
namespace FilterCells
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Workbook object
            Workbook workbook = new Workbook();
            //Load the Excel file
            workbook.LoadFromFile("sample.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Create an auto filter in the sheet and specify the range to be filterd
            sheet.AutoFilters.Range = sheet.Range["A1:A9"];
            //Get the coloumn to be filterd
            FilterColumn filtercolumn = (FilterColumn)sheet.AutoFilters[0];
            //Add a color filter to filter the column based on cell color
            sheet.AutoFilters.AddFillColorFilter(filtercolumn, Color.Red);

            //Filter the data
            sheet.AutoFilters.Filter();

            //Save the file
            workbook.SaveToFile("ColorFilter.xlsx", ExcelVersion.Version2013);
        }
    }
}

How to Add Auto Filters in Excel Using C#

Want to make your Excel data easier to explore and analyze? Auto Filters are your go-to tool. With just a few clicks, you can sort, filter and focus on the rows that matter. In this guide, you’ll learn how to add filters in Excel with C# using Spire.XLS for .NET, making it easy to insert Auto Filters into your spreadsheets. As a bonus, we’ll also show you how to remove Auto Filters in Excel when you're done.

Let’s dive in and make your spreadsheets smarter!

What is Spire.XLS and Why Use It

Spire.XLS for .NET is a powerful Excel library that enables you to create, edit, and convert Excel files programmatically — no need for Microsoft Excel to be installed on your machine. It’s ideal for automating Excel tasks in C# and other .NET applications.

To get started, you can install the library via NuGet with the following command:

PM> Install-Package Spire.XLS

For smaller or lightweight Excel projects, the free version is available:

PM> Install-Package FreeSpire.XLS

If you prefer manual setup or need more installation options, you can also download Spire.XLS for .NET or Free Spire.XLS for .NET directly from the official website.

How to Add Auto Filters to a Cell Range in Excel

If you want to quickly filter data in an Excel sheet without writing formulas, Auto Filters will help to instantly display only the needed rows. In this section, you'll learn how to add Auto Filters to a specific cell range in Excel using C#. Whether you're working with a small table or a large dataset, this method helps streamline data analysis with just a few lines of code.

The steps to apply Auto Filters to a cell range with C#:

  • Create a Workbook instance and read an Excel file.
  • Get a certain worksheet.
  • Add an AutoFilter to a specified cell range using Worksheet.AutoFilters.Range property.
  • Save the modified Excel file.

Here’s a code example showing how to add an Auto Filter in the cell range “A1:C1”:

  • C#
using Spire.Xls;

namespace AddAutoFilter
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook instance
            Workbook workbook = new Workbook();

            // Load an Excel file
            workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\Data.xlsx");

            // Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            // Create an AutoFilter in the sheet and specify the range to be filtered
            sheet.AutoFilters.Range = sheet.Range["A1:C1"];

            // Save the result file
            workbook.SaveToFile("ExcelAutoFilter.xlsx", ExcelVersion.Version2016);
        }
    }
}

Using C# to Add Excel Autofilters

How to Add Built-in Auto Filters in Excel - Date

Excel’s built-in Auto Filters make it easy to filter data by common criteria like dates, numbers, and text. In this part, we’ll show you how to add a date Auto Filter in Excel using C#. The example focuses on applying a filter to a date column so you can quickly display rows based on specific days, months, or years.

  • Create a Workbook instance and load a sample Excel spreadsheet.
  • Get a worksheet and apply filters to a cell range through Worksheet.AutoFilters.Range property.
  • Add a date filter to the cell range with Workbook.AutoFilters.AddDateFilter() method.
  • Apply the date filter using Workbook.AutoFilters.Filter() method.
  • Save the updated Excel file.
  • C#
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.AutoFilter;

namespace AddAutoFilter
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook instance
            Workbook workbook = new Workbook();

            // Load an Excel file
            workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\Data.xlsx");

            // Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            // Create an auto filter in the sheet and specify the range to be filtered
            sheet.AutoFilters.Range = sheet.Range["A1:A12"];

            // Get the column to be filtered
            IAutoFilter filtercolumn = sheet.AutoFilters[0];

            // Add a date filter to filter data related to February 2022
            sheet.AutoFilters.AddDateFilter(filtercolumn, DateTimeGroupingType.Month, 2022, 2, 0, 0, 0, 0);

            // Apply the filter
            sheet.AutoFilters.Filter();

           // Save the result file
            workbook.SaveToFile("DateAutoFilter.xlsx", ExcelVersion.Version2016);
        }
    }
}

Insert a Date Auto Filter to an Excel File Using C#

Quickly Apply Custom AutoFilter in Excel in C#

While built-in filters like date filters offer quick presets, there are times when you need more control over what gets displayed. That’s where custom AutoFilters come in. In this section, we’ll show you how to add a custom AutoFilter in Excel using C#, allowing you to filter by specific values or conditions — such as greater than, contains, or equals — to fit more complex data scenarios.

Steps to apply custom Auto Filters in Excel:

  • Create a Workbook object and load an Excel file.
  • Retrieve a worksheet.
  • Add an Auto Filter to a cell range.
  • Add a custom filter to the cell range through Workbook.AutoFilters.CustomFilter() method.
  • Apply the filter using Workbook.AutoFilters.Filter() method.
  • Save the resulting file.
  • C#
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.AutoFilter;

namespace AddAutoFilter
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook instance
            Workbook workbook = new Workbook();

            // Load an Excel file
            workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\Data.xlsx");

            // Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            // Create an auto filter in the sheet and specify the range to be filtered
            sheet.AutoFilters.Range = sheet.Range["G1:G12"];

            // Get the column to be filtered
            FilterColumn filtercolumn = (FilterColumn)sheet.AutoFilters[0];

            // Add a custom filter to filter data containing the string "Grocery"
            string strCrt = "Grocery";
            sheet.AutoFilters.CustomFilter(filtercolumn, FilterOperatorType.Equal, strCrt);

            // Apply the filter
            sheet.AutoFilters.Filter();

           // Save the result file
            workbook.SaveToFile("CustomAutoFilter.xlsx", ExcelVersion.Version2016);
        }
    }
}

How to Add Customized Auto Filters in Excel with C#

Bonus Tip: How to Remove AutoFilters in Excel

Once you're done filtering, removing AutoFilters in Excel is just as easy. You can clear filters from a worksheet using a single line of C# code. This helps reset the view and ensures your data is fully visible again.

Want the exact steps? Check out our full guide on how to remove AutoFilters in Excel, including detailed instructions and code samples.

Wrapping Up

Adding AutoFilters in Excel using C# doesn’t have to be complicated — whether you’re working with a standard cell range, dates, or applying custom filter criteria. With just a few lines of code, you can make your Excel spreadsheets far more interactive and easier to analyze.

FAQ: Excel AutoFilter Questions Answered

Q1: How do I quickly add filters in Excel using C#?

You can quickly add filters to a cell range in Excel by using the Worksheet.AutoFilters.Range property in C#. Just define the target range and apply the filter with a single line of code.

Q2: How do I insert a drop-down filter in Excel?

Excel AutoFilters are essentially drop-down filters. Once you apply an AutoFilter to a column, Excel automatically creates a drop-down menu that lets you sort or filter the data based on values, conditions, or custom criteria.

Q3: How do I add a drop-down slicer in Excel?

Slicers are a visual filtering tool mainly used with PivotTables. While AutoFilters apply to standard worksheets, slicers offer a more user-friendly UI for filtering PivotTable data. If you're working with regular data (not PivotTables), AutoFilters are the better choice.

Q4: Can I remove filters once they’re applied in Excel with C#?

Yes, you can easily remove filters using C#. Just call the Worksheet.AutoFilters.Clear() method to remove all active filters from your worksheet.

The height of headers and footers can be adjusted by using the HeaderDistance and the FooterDistance properties. The detail steps of how to adjust the height of headers and footers in a word document using Spire.Doc are shown below.

Detail steps:

Step 1: Instantiate a Document object and load the word document.

Document doc = new Document();
doc.LoadFromFile("Headers and Footers.docx");

Step 2: Get the first section.

Section section = doc.Sections[0];

Step 3: Adjust the height of headers and footers in the section.

section.PageSetup.HeaderDistance = 100;
section.PageSetup.FooterDistance = 100;

Step 4: Save the file.

doc.SaveToFile("Output.docx", FileFormat.Docx2013);

Screenshot:

Header:

Adjust the Height of Headers and Footers in a Word document in C#

Footer:

Adjust the Height of Headers and Footers in a Word document in C#

Full code:

//Instantiate a Document object
Document doc = new Document();
//Load the word document
doc.LoadFromFile("Headers and Footers.docx");

//Get the first section
Section section = doc.Sections[0];

//Adjust the height of headers in the section
section.PageSetup.HeaderDistance = 100;

//Adjust the height of footers in the section
section.PageSetup.FooterDistance = 100;

//Save the document
doc.SaveToFile("Output.docx", FileFormat.Docx2013);
page 14