Knowledgebase (2311)
Children categories
Adjust the Height of Headers and Footers in a Word document in C#
2018-08-16 02:52:41 Written by KoohjiThe 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:

Footer:

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);
A table in Excel is a structured range of data that includes headers for each column. When you convert a range of cells into a table, Excel automatically applies formatting, adds filter arrows to each header cell, and provides enhanced features for manipulating and analyzing the data. In this article, we will explain how to create, resize, and remove tables in Excel in C# using Spire.XLS for .NET.
- Create a Table in Excel in C#
- Add a Total Row to a Table in Excel in C#
- Resize a Table in Excel in C#
- Remove a Table from Excel in C#
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 DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Create a Table in Excel in C#
Spire.XLS for .NET allows you to convert a specific range of data in an Excel worksheet to a table using the Worksheet.ListObjects.Create(tableName, cellRange) method. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet using Workbook.Worksheets[index] property.
- Get the cell range you want to convert to a table using Worksheet.Range[] property.
- Convert the cell range to a table using Worksheet.ListObjects.Create(tableName, cellRange) method.
- Save the resulting workbook to a file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace CreateTable
{
internal class Program
{
static void Main(string[] args)
{
//Create an object of the Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("Sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the cell range you want to convert to a table
CellRange range = sheet.Range[1, 1, sheet.LastRow, sheet.LastColumn];
//Convert the cell range to a table
IListObject table = sheet.ListObjects.Create("SalesTransactions", range);
//Format the table with a built-in table style
table.BuiltInTableStyle = TableBuiltInStyles.TableStyleLight2;
//Save the resulting workbook to a file
workbook.SaveToFile("CreateTable.xlsx", ExcelVersion.Version2016);
workbook.Dispose();
}
}
}

Add a Total Row to a Table in Excel in C#
You can add a total row after the end of a table to display summary calculations, such as sums, averages, or other aggregations of the data in the table. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet using Workbook.Worksheets[index] property.
- Get a specific table in the worksheet using Worksheet.ListObjects[index] property.
- Display a total row at the end of the table by setting Table.DisplayTotalRow property to true.
- Set total row label in a specific table column using IListObject.Columns[index].TotalsRowLabel property.
- Set the calculation functions for specific table columns using IListObject.Columns[index].TotalsCalculation property.
- Save the resulting workbook to a file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace AddTotalRowToTable
{
internal class Program
{
static void Main(string[] args)
{
//Create an object of the Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("CreateTable.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the first table in the worksheet
IListObject table = sheet.ListObjects[0];
//Show total row
table.DisplayTotalRow = true;
// Set total row label
table.Columns[0].TotalsRowLabel = "Total";
//Set the function used for the total calculation
table.Columns[3].TotalsCalculation = ExcelTotalsCalculation.Sum;
table.Columns[4].TotalsCalculation = ExcelTotalsCalculation.Sum;
//Save the resulting workbook to a file
workbook.SaveToFile("AddTotalRow.xlsx", ExcelVersion.Version2016);
workbook.Dispose();
}
}
}

Resize a Table in Excel in C#
You can resize a table by updating the data range of it using IListObject.Location property. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet using Workbook.Worksheets[index] property.
- Get a specific table in the worksheet using Worksheet.ListObjects[index] property.
- Resize the table by updating the data range of it using IListObject.Location property.
- Save the resulting workbook to a file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace ResizeTable
{
internal class Program
{
static void Main(string[] args)
{
//Create an object of the Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("CreateTable.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the first table in the worksheet
IListObject table = sheet.ListObjects[0];
table.Location = sheet.Range["C1:E8"];
//Save the resulting workbook to a file
workbook.SaveToFile("ResizeTable.xlsx", ExcelVersion.Version2016);
workbook.Dispose();
}
}
}

Remove a Table from Excel in C#
If you no longer need a table, you can convert it back to a normal range of cells by using the IListObjects.RemoveAt(tableIndex) method. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet using Workbook.Worksheets[index] property.
- Get the table collection of the worksheet using Worksheet.ListObjects property.
- Remove a specific table from the table collection using IListObjects.RemoveAt(tableIndex) property.
- Save the resulting workbook to a file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace RemoveTable
{
internal class Program
{
static void Main(string[] args)
{
//Create an object of the Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("CreateTable.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the table collection of the worksheet
IListObjects tables = sheet.ListObjects;
//Remove a specific table by its index
tables.RemoveAt(0);
////Or remove a specific table by its name
//for (int i = tables.Count - 1; i >= 0; i--)
//{
// // Check if the table name matches the specific value
// if (tables[i].Name == "SalesTransactions")
// {
// // Remove the table
// tables.RemoveAt(i);
// }
//}
//Save the resulting workbook to a file
workbook.SaveToFile("RemoveTable.xlsx", ExcelVersion.Version2016);
workbook.Dispose();
System.Diagnostics.Process.Start("RemoveTable.xlsx");
}
}
}

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.
In Spire.Presentation, when we add a common animation effect that belongs to both entrance and exit types, it’s applied as entrance effect by default. This article is going to show you how to add exit animation effect to a shape in PowerPoint using Spire.Presentation.
Detail steps:
Step 1: Create a Presentation instance and get the first slide.
Presentation ppt = new Presentation(); ISlide slide = ppt.Slides[0];
Step 2: Add a shape to the slide.
IShape starShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 100, 200, 200));
Step 3: Add random bars effect to the shape.
AnimationEffect effect = slide.Timeline.MainSequence.AddEffect(starShape, AnimationEffectType.RandomBars);
Step 4: Change the type of the effect from entrance to exit.
effect.PresetClassType = TimeNodePresetClassType.Exit;
Step 5: Save the file.
ppt.SaveToFile("ExitAnimationEffect.pptx", FileFormat.Pptx2013);
Screenshot:

Full code:
using Spire.Presentation;
using Spire.Presentation.Drawing.Animation;
using System.Drawing;
namespace AddExitAnimationEffect
{
class Program
{
static void Main(string[] args)
{
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Get the first slide
ISlide slide = ppt.Slides[0];
//Add a shape to the slide
IShape starShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 100, 200, 200));
//Add random bars effect to the shape
AnimationEffect effect = slide.Timeline.MainSequence.AddEffect(starShape, AnimationEffectType.RandomBars);
//Change effect type from entrance to exit
effect.PresetClassType = TimeNodePresetClassType.Exit;
//Save the file
ppt.SaveToFile("ExitAnimationEffect.pptx", FileFormat.Pptx2013);
}
}
}
}