Other

Other (4)

We have already demonstrated whether to display the additional information for presentation slides on header and footer area, such as hide or display date and time, the slide number, and the footer with the help of Spire.Presentation. This article will show you how to reset the position of the slide number and the date time in C#. We will also demonstrate how to reset the display format for the date and time from MM/dd/yyyy to yy.MM.yyyy on the presentation slides.

Firstly, view the default position of the date time at the left and the slide number at the right.

How to reset the position of the date time and slide number for the presentation slides

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

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

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

ISlide slide = presentation.Slides[0];

Step 3: Reset the position of the slide number to the left and date time to the center, and reset the date time display style.

foreach (IShape shapeToMove in slide.Shapes)
{
    if (shapeToMove.Name.Contains("Slide Number Placeholder"))
    {
        shapeToMove.Left =0;                                                  
     }

    else if (shapeToMove.Name.Contains("Date Placeholder"))
    {
        shapeToMove.Left = presentation.SlideSize.Size.Width / 2;
       
        (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
        (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
    }
}

Step 4: Save the document to file.

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

Effective screenshot after reset the position and the format for the date time and slide number.

How to reset the position of the date time and slide number for the presentation slides

Full codes of how to reset the position of slide number and date time:

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

ISlide slide = presentation.Slides[0];        

foreach (IShape shapeToMove in slide.Shapes)
{
    if (shapeToMove.Name.Contains("Slide Number Placeholder"))
    {
        shapeToMove.Left = 0;                                                  
        
    }

    else if (shapeToMove.Name.Contains("Date Placeholder"))
    {
        shapeToMove.Left = presentation.SlideSize.Size.Width / 2;
       
        (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
        (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
    }
    
}
presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);

When we operate the Microsoft PowerPoint documents, we can set whether to show some additional information of slides to readers, such as “Date and Time”, “Slide number” and footer. This article will demonstrate how to set whether to show these information to readers in C# with the help of Spire.Presentation.

Firstly, view the screenshot of the property of slide appearance on the header and footer area.

Whether to display the additional information for presentation slides on header and footer area

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

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

Step 2: Set the appearance property for slide number, footer and date time.

ppt.SlideNumberVisible = true;

ppt.FooterVisible = false;

ppt.DateTimeVisible = false;

Step 3: Save the document to file.

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

Effective screenshot of the slide appearance on header and footer area.

Whether to display the additional information for presentation slides on header and footer area

Full codes of how to set the additional information of presentation slides’ header and footer area:

{

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

    ppt.SlideNumberVisible = true;

    ppt.FooterVisible = false;

    ppt.DateTimeVisible = false;
    
    ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
  
 }

To display Excel data in a PowerPoint presentation, we can copy and paste the data to a slide as a PowerPoint table, a worksheet object, a picture, or plain text. This article introduces how to insert an Excel sheet in PowerPoint as an OLE object in C# and VB.NET.

In this solution, you'll need to use Spire.XLS to load the Excel file and get the data, and then create OEL object using Spire.Presentation. So, please download Spire.Office and reference the related DLLs in your project.

Workbook book = new Workbook();
book.LoadFromFile(@"data.xlsx");

Step 2: Select the cell range from the first worksheet and save it as image.

Image image = book.Worksheets[0].ToImage(1, 1, 5, 4);

Step 3: Initialize a new instance of Presentation class, add the image to presentation.

Presentation ppt = new Presentation();
IImageData oleImage = ppt.Images.Append(image);

Step 4: Insert an OLE object to presentation based on the Excel data.

Rectangle rec = new Rectangle(60,60,image.Width,image.Height);
using (MemoryStream ms = new MemoryStream())
{
    book.SaveToStream(ms);
    ms.Position = 0;
    Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);
    oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
    oleObject.ProgId = "Excel.Sheet.12";
}

Step 5: Save the PowerPoint file with the specified format.

ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007);

Output:

How to Embed Excel Object into PowerPoint Slide in C#, VB.NET

Entire Code:

[C#]
Workbook book = new Workbook();
book.LoadFromFile(@"data.xlsx");
Image image = book.Worksheets[0].ToImage(1, 1, 5, 4);

Presentation ppt = new Presentation();
IImageData oleImage = ppt.Images.Append(image);
Rectangle rec = new Rectangle(60,60,image.Width,image.Height);
using (MemoryStream ms = new MemoryStream())
{
    book.SaveToStream(ms);
    ms.Position = 0;
    Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);
    oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
    oleObject.ProgId = "Excel.Sheet.12";
}

ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007);
[VB.NET]
Dim book As New Workbook()
book.LoadFromFile("data.xlsx")
Dim image As Image = book.Worksheets(0).ToImage(1, 1, 5, 4)

Dim ppt As New Presentation()
Dim oleImage As IImageData = ppt.Images.Append(image)
Dim rec As New Rectangle(60, 60, image.Width, image.Height)
Using ms As New MemoryStream()
	book.SaveToStream(ms)
	ms.Position = 0
	Dim oleObject As Spire.Presentation.IOleObject = ppt.Slides(0).Shapes.AppendOleObject("excel", ms.ToArray(), rec)
	oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage
	oleObject.ProgId = "Excel.Sheet.12";
End Using

ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007)
Wednesday, 07 May 2014 01:32

Add footer into a PowerPoint document

Written by support iceblue

Footer is area in the bottom of each slide in a PPT document. The Spire.Presentation supports user to insert text or graphics in footer. For example, you can add slide numbers, the time and date, a company logo, the document title or the file name, or the author's name in document.

Spire.Presentation for .NET, a reliable .NET PPT component, enables you to generate, read, edit, convert even print your PPT document in a fast speed. Using Spire.Presentation for .NET, you can add footer in your PPT document with C#, VB. Please see the target PPT document with footer as below picture:

Add footer into a PPT document

This guide will introduce the method to add footer in your PPT document with C#, VB.NET via Spire.Presentation for .NET.

The method main steps are:

Step 1: create a PPT document.

Presentation presentation = new Presentation();

Step 2: set background Image and slide.

string ImageFile = @"bg.png";   
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

Step 3: add and set the footer and set whether show date and page number.

presentation.SetFooterText("Demo of Spire.Presentation");
presentation.SetFooterVisible(true);
presentation.SetSlideNoVisible(true);
presentation.SetDateTimeVisible(true);

Step 4: save the document.

presentation.SaveToFile("HeaderAndFooter.pptx", FileFormat.Pptx2007);

Download and install Spire.Presentation for .NET and use below code to experience this method to add footer in PPT document.

The full code:

[C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Drawing;
namespace AddheadersAndfooters
{
    class Program
    {
        static void Main(string[] args)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string ImageFile = @"bg.png";
            RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //add footer
            presentation.SetFooterText("Demo of Spire.Presentation");

            //set the footer visible
            presentation.SetFooterVisible(true);

            //set the page number visible
            presentation.SetSlideNoVisible(true);

            //set the date visible
            presentation.SetDateTimeVisible(true);

            //append new shape
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 250));
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("The sample demonstrates how to use Footer.");

            //append new Paragraph
            shape.TextFrame.Paragraphs.Append(new TextParagraph());

            //add text to Paragraph
            shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("Spire.Office for .NET is a compilation of Enterprise-Level Office .NET component offered by E-iceblue. It includes Spire.Doc, Spire XLS, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer, and Spire.BarCode. Spire.Office contains the most up-to-date versions of the above .NET components."));
            //set the Font
            foreach (TextParagraph para in shape.TextFrame.Paragraphs)
            {
                para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
                para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                para.Alignment = TextAlignmentType.Left;
                para.Indent = 35;
            }
            //save the document
            presentation.SaveToFile("HeaderAndFooter.pptx", FileFormat.Pptx2007);
            System.Diagnostics.Process.Start("HeaderAndFooter.pptx");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Presentation.Drawing
Imports Spire.Presentation
Module Module1

    Sub Main()
        'create PPT document
        Dim presentation As New Presentation()

        'set background Image
        Dim ImageFile As String = "D:\Spire.Presentation\Demos\Data\bg.png"
        Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height)
        presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect)
        presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite

        'add footer
        presentation.SetFooterText("Demo of Spire.Presentation")

        'set the footer visible
        presentation.SetFooterVisible(True)

        'set the page number visible
        presentation.SetSlideNoVisible(True)

        'set the date visible
        presentation.SetDateTimeVisible(True)

        'append new shape
        Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 600, 250))
        shape.ShapeStyle.LineColor.Color = Color.White
        shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None

        'add text to shape
        shape.AppendTextFrame("The sample demonstrates how to use Footer.")

        'append new Paragraph
        shape.TextFrame.Paragraphs.Append(New TextParagraph())

        'add text to Paragraph
        shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange("Spire.Office for .NET is a compilation of Enterprise-Level Office .NET component offered by E-iceblue. It includes Spire.Doc, Spire XLS, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer, and Spire.BarCode. Spire.Office contains the most up-to-date versions of the above .NET components."))

        'set the Font
        For Each para As TextParagraph In shape.TextFrame.Paragraphs
            para.TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold")
            para.TextRanges(0).Fill.FillType = FillFormatType.Solid
            para.TextRanges(0).Fill.SolidColor.Color = Color.Black
            para.Alignment = TextAlignmentType.Left
            para.Indent = 35
        Next
        'save the document
        presentation.SaveToFile("HeaderAndFooter.pptx", FileFormat.Pptx2007)
        System.Diagnostics.Process.Start("HeaderAndFooter.pptx")
    End Sub
End Module

If you couldn't successfully use the Spire.presentation, please refer the Spire.Presentation Quick Start which can guide you quickly use the Spire.presentation.