Knowledgebase (2330)
Children categories
In MS Word page border options, there are checkboxes to choose whether page border surrounds header/footer or not. This feature is very important for which can be used to manage the positional relation between page border and header/footer. Spire.Doc supports to set the two frequently-used features: page border and header/footer, and it supports to manage their spatial relations, too. This article is going to introduce the method to set whether page border surrounds header/footer or not.
Note: before start, please download the latest version of Spire.Doc and add the .dll in the bin folder as the reference of Visual Studio.
Step 1: Create a Word document and add a section.
Document document = new Document();
Section section = document.AddSection();
Step 2: Add a sample page border to the document using Spire.Doc library.
section.PageSetup.Borders.BorderType = BorderStyle.Wave;
section.PageSetup.Borders.Color = Color.Green;
section.PageSetup.Borders.Left.Space = 20;
section.PageSetup.Borders.Right.Space = 20;
Step 3: Add sample header and footer to the document using Spire.Doc library.
//add a header and set its format
Paragraph paragraph1 = section.HeadersFooters.Header.AddParagraph();
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right;
TextRange headerText = paragraph1.AppendText("Header isn't included in page border");
headerText.CharacterFormat.FontName = "Calibri";
headerText.CharacterFormat.FontSize = 20;
headerText.CharacterFormat.Bold = true;
//add a footer and set its format
Paragraph paragraph2 = section.HeadersFooters.Footer.AddParagraph();
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange footerText = paragraph2.AppendText("Footer is included in page border");
footerText.CharacterFormat.FontName = "Calibri";
footerText.CharacterFormat.FontSize = 20;
footerText.CharacterFormat.Bold = true;
Step 4: Set the header not included in the page border while the footer included.
section.PageSetup.PageBorderIncludeHeader = false;
section.PageSetup.HeaderDistance = 40;
section.PageSetup.PageBorderIncludeFooter = true;
section.PageSetup.FooterDistance = 40;
Step 5: Save the document and launch to see effect.
document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");
Effects:

Full Codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Mirror_Margin
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
Section section = document.AddSection();
section.PageSetup.Borders.BorderType = BorderStyle.Wave;
section.PageSetup.Borders.Color = Color.Green;
section.PageSetup.Borders.Left.Space = 20;
section.PageSetup.Borders.Right.Space = 20;
Paragraph paragraph1 = section.HeadersFooters.Header.AddParagraph();
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right;
TextRange headerText = paragraph1.AppendText("Header isn't included in page border");
headerText.CharacterFormat.FontName = "Calibri";
headerText.CharacterFormat.FontSize = 20;
headerText.CharacterFormat.Bold = true;
Paragraph paragraph2 = section.HeadersFooters.Footer.AddParagraph();
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange footerText = paragraph2.AppendText("Footer is included in page border");
footerText.CharacterFormat.FontName = "Calibri";
footerText.CharacterFormat.FontSize = 20;
footerText.CharacterFormat.Bold = true;
section.PageSetup.PageBorderIncludeHeader = false;
section.PageSetup.HeaderDistance = 40;
section.PageSetup.PageBorderIncludeFooter = true;
section.PageSetup.FooterDistance = 40;
document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");
}
}
}
How to add a picture to the chart and then assign a hyperlink to the picture
2015-07-21 01:22:54 Written by KoohjiOne of our users requests a demo of Spire.XLS for how to add a picture to the chart at a specified location and then assign a hyperlink to the picture in C#. To fulfil it, we need to prepare the two things. Firstly, we need to know how to create Excel Charts in C# with the help of Spire.XLS. Secondly, we should have an image that we use to insert to the chart. We will use Excel Column chart for example.
Here comes to the steps. Firstly, please review the sample excel chart that we will add image later.

Step 1: Create a new document and load from file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Step 2: Get the first worksheet and the first chart in it.
Worksheet workSheet = workbook.Worksheets[0]; Chart chart = workSheet.Charts[0];
Step 3: Add the desired image into the chart and set the image's position and size.
IPictureShape ps = chart.Shapes.AddPicture("1.png");
ps.Top = 180;
ps.Left = 280;
ps.Width = 60;
ps.Height = 80;
Step 4: Assign a hyperlink to the image.
(ps as XlsBitmapShape).SetHyperLink("https://en.wikipedia.org/wiki/United_States", true);
Step 5: Save the document to file.
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
Effective screenshot of adding an image to the chart and assign a hyperlink to the image:

Full codes:
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.Shapes;
namespace AddPicturetoChart
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet workSheet = workbook.Worksheets[0];
Chart chart = workSheet.Charts[0];
IPictureShape ps = chart.Shapes.AddPicture("1.png");
ps.Top = 180;
ps.Left = 280;
ps.Width = 60;
ps.Height = 80;
(ps as XlsBitmapShape).SetHyperLink("https://en.wikipedia.org/wiki/United_States", true);
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
}
}
}
Slide cloning feature provided by Spire.Presentation enables developers to clone one or several slides within one PowerPoint presentation or among multiple presentations. By cloning slide from source presentation to target document, we can easily split a large presentation into small ones and merge multiple presentations to one presentation in reverse. This article presents how to merge selected slides from multiple PowerPoint presentations into one single presentation.
Main Steps
Step 1: Create a new PowerPoint document and remove the default blank slide.
Presentation ppt = new Presentation(); ppt.Slides.RemoveAt(0);
Step 2: Initialize two instances of Presentation class and load the sample PowerPoint file respectively.
Presentation ppt1 = new Presentation("sample_01.pptx",FileFormat.Pptx2010);
Presentation ppt2 = new Presentation("sample_02.pptx", FileFormat.Pptx2010);
Step 3: Append all slides in sample_01 to the new PowerPoint document using method Append(ISlide slide).
for (int i = 0; i < ppt1.Slides.Count; i++)
{
ppt.Slides.Append(ppt1.Slides[i]);
}
Step 4: Append the second slide in sample_02 to the new presentation.
ppt.Slides.Append(ppt2.Slides[1]);
Step 5: Save and launch the file.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
Output

Entire Code
using Spire.Presentation;
namespace MergeSlides
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
Presentation ppt1 = new Presentation("sample_01.pptx", FileFormat.Pptx2010);
Presentation ppt2 = new Presentation("sample_02.pptx", FileFormat.Pptx2010);
ppt.Slides.RemoveAt(0);
//append all slides in ppt1 to ppt
for (int i = 0; i < ppt1.Slides.Count; i++)
{
ppt.Slides.Append(ppt1.Slides[i]);
}
//append the second slide in ppt2 to ppt
ppt.Slides.Append(ppt2.Slides[1]);
//save and launch the file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
}
}
}
Imports Spire.Presentation
Namespace MergeSlides
Class Program
Private Shared Sub Main(args As String())
Dim ppt As New Presentation()
Dim ppt1 As New Presentation("sample_01.pptx", FileFormat.Pptx2010)
Dim ppt2 As New Presentation("sample_02.pptx", FileFormat.Pptx2010)
ppt.Slides.RemoveAt(0)
'append all slides in ppt1 to ppt
For i As Integer = 0 To ppt1.Slides.Count - 1
ppt.Slides.Append(ppt1.Slides(i))
Next
'append the second slide in ppt2 to ppt
ppt.Slides.Append(ppt2.Slides(1))
'save and launch the file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010)
System.Diagnostics.Process.Start("result.pptx")
End Sub
End Class
End Namespace