News Category

In a PowerPoint document, the footer is an area located at the bottom of each slide, typically containing textual information such as page numbers, dates, authors, and more. By adding a footer, you can give your slides a professional look and provide important information. Modifying the footer allows you to adjust the displayed content, style, and position to meet specific needs or styles. Removing the footer can clear the bottom content when extra information is not needed or to maintain a clean appearance. This article will introduce how to use Spire.Presentation for Python to add, modify, or remove footers in PowerPoint documents within a Python project.

Install Spire.Presentation for Python

This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your VS Code through the following pip command.

pip install Spire.Presentation

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python in VS Code

Python Add Footers in PowerPoint Documents

Using Spire.Presentation, you can add footers, page numbers, and time information to the bottom of each page in a PowerPoint document, ensuring consistent footer content across all pages. Here are the detailed steps:

  • Create a lisentation object.
  • Load a PowerPoint document using the lisentation.LoadFromFile() method.
  • Set the footer visible using lisentation.FooterVisible = true and set the footer text.
  • Set the slide number visible using lisentation.SlideNumberVisible = true, iterate through each slide, check for the lisence of a page number placeholder, and modify the text to the "Page X" format if found.
  • Set the date visible using lisentation.DateTimeVisible = true.
  • Set the format of the date using the lisentation.SetDateTime() method.
  • Save the document using the lisentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load the presentation from a file
presentation.LoadFromFile("Sample1.pptx")

# Set the footer visible
presentation.FooterVisible = True

# Set the footer text to "Spire.Presentation"
presentation.SetFooterText("Spire.Presentation")

# Set the slide number visible
presentation.SlideNumberVisible = True

# Iterate through each slide in the presentation
for slide in presentation.Slides:
    for shape in slide.Shapes:
        if shape.IsPlaceholder:
            # If it is a slide number placeholder
            if shape.Placeholder.Type == PlaceholderType.SlideNumber:
                autoShape = shape if isinstance(shape, IAutoShape) else None
                if autoShape is not None:
                    text = autoShape.TextFrame.TextRange.Paragraph.Text

                    # Modify the slide number text to "Page X"
                    autoShape.TextFrame.TextRange.Paragraph.Text = "Page " + text

# Set the date and time visible
presentation.DateTimeVisible = True

# Set the date and time format
presentation.SetDateTime(DateTime.get_Now(), "MM/dd/yyyy")

# Save the modified presentation to a file
presentation.SaveToFile("AddFooter.pptx", FileFormat.Pptx2016)

# Dispose of the Presentation object resources
presentation.Dispose()

Python: Add, Modify, or Remove Footers from Powerpoint Documents

Python Modify Footers in PowerPoint Documents

To modify the footer in a PowerPoint document, you first need to inspect the elements of each slide to locate footer and page number placeholders. Then, for each type of placeholder, set the desired content and format to ensure consistent and compliant footers throughout the document. Here are the detailed steps:

  • Create a Presentation object.
  • Load a PowerPoint document using the Presentation.LoadFromFile() method.
  • Use the Presentation.Slides[index] property to retrieve a slide.
  • Iterate through the shapes in the slide using a for loop, check each shape to determine if it is a placeholder such as a footer or page number placeholder, and then modify its content or format accordingly.
  • Save the document using the Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

def change_font(paragraph):
    for textRange in paragraph.TextRanges:
        # Set the text style to italic
        textRange.IsItalic = TriState.TTrue

        # Set the text font
        textRange.EastAsianFont = TextFont("Times New Roman")

        # Set the text font size to 12
        textRange.FontHeight = 34

        # Set the text color
        textRange.Fill.FillType = FillFormatType.Solid
        textRange.Fill.SolidColor.Color = Color.get_SkyBlue()

# Create a Presentation object
presentation = Presentation()

# Load a presentation from a file
presentation.LoadFromFile("Sample2.pptx")

# Get the first slide
slide = presentation.Slides[0]

# Iterate through the shapes on the slide
for shape in slide.Shapes:
   # Check if the shape is a placeholder
   if shape.Placeholder is not None:
       # Get the placeholder type
       type = shape.Placeholder.Type

       # If it is a footer placeholder
       if type == PlaceholderType.Footer:
           # Convert the shape to IAutoShape type
            autoShape = shape if isinstance(shape, IAutoShape) else None
            if autoShape is not None:
                # Set the text content to "E-ICEBLUE"
                autoShape.TextFrame.Text = "E-ICEBLUE"

                # Modify the text font
                change_font(autoShape.TextFrame.Paragraphs[0])
       
       # If it is a slide number placeholder
       if type == PlaceholderType.SlideNumber:
            # Convert the shape to IAutoShape type
            autoShape = shape if isinstance(shape, IAutoShape) else None
            if autoShape is not None:
                # Modify the text font
                change_font(autoShape.TextFrame.Paragraphs[0])

# Save the modified presentation to a file
presentation.SaveToFile("ModifiedFooter.pptx", FileFormat.Pptx2016)

# Release the resources of the Presentation object
presentation.Dispose()

Python: Add, Modify, or Remove Footers from Powerpoint Documents

Python Remove Footers in PowerPoint Documents

To delete footers in a PowerPoint document, you first need to locate placeholders such as footers, page numbers, and time in the slides, and then remove them from the collection of shapes in the slide to ensure complete removal of footer content. Here are the detailed steps:

  • Create a Presentation object.
  • Load a PowerPoint document using the Presentation.LoadFromFile() method.
  • Use the Presentation.Slides[index] property to retrieve a slide.
  • Iterate through the shapes in the slide using a for loop, check if they are placeholders, and if they are footer placeholders, page number placeholders, or time placeholders, remove them from the slide.
  • Save the document using the Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a presentation from a file
presentation.LoadFromFile("Sample2.pptx")

# Get the first slide
slide = presentation.Slides[0]

# Iterate through the shapes on the slide
for i in range(len(slide.Shapes) - 1, -1, -1):
    # Check if the shape is a placeholder
    if slide.Shapes[i].Placeholder is not None:
        # Get the placeholder type
        type = slide.Shapes[i].Placeholder.Type

        # If it is a footer placeholder
        if type == PlaceholderType.Footer:
            # Remove it from the slide
            slide.Shapes.RemoveAt(i)

        # If it is a slide number placeholder
        if type == PlaceholderType.SlideNumber:
            # Remove it from the slide
            slide.Shapes.RemoveAt(i)

        # If it is a date and time placeholder
        if type == PlaceholderType.DateAndTime:
            # Remove it from the slide
            slide.Shapes.RemoveAt(i)

# Save the modified presentation to a file
presentation.SaveToFile("RemovedFooter.pptx", FileFormat.Pptx2016)

# Release the resources of the Presentation object
presentation.Dispose()

Python: Add, Modify, or Remove Footers from Powerpoint Documents

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.

The AutoFit feature in Microsoft Excel is a handy tool that allows you to automatically adjust the height of rows or the width of columns in an Excel spreadsheet to fit the content within them. This feature is particularly useful when you have data that may vary in length or when you want to ensure that all the content is visible without having to manually adjust the column widths or row heights. In this article, we will explain how to AutoFit rows and columns in Excel in Python using Spire.XLS for Python.

Install Spire.XLS for Python

This scenario requires Spire.XLS for Python and plum-dispatch v1.7.4. They can be easily installed in your VS Code through the following pip command.

pip install Spire.XLS

If you are unsure how to install, please refer to this tutorial: How to Install Spire.XLS for Python in VS Code

AutoFit a Specific Row and Column in Python

To AutoFit a specific row and column in an Excel worksheet, you can use the Worksheet.AutoFitRow() and Worksheet.AutoFitColumn() methods. 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.
  • AutoFit a specific row and column in the worksheet by its index (1-based) using Worksheet.AutoFitRow(rowIndex) and Worksheet.AutoFitColumn(columnIndex) methods.
  • Save the result file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create an object of the Workbook class
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")
 
# Get the first worksheet
sheet = workbook.Worksheets[0]
 
# Automatically adjust the height of the 3rd row in the worksheet 
sheet.AutoFitRow(3)
# Automatically adjust the width of the 4th column in the worksheet
sheet.AutoFitColumn(4)
 
# Save the resulting file
workbook.SaveToFile("AutoFitSpecificRowAndColumn.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: AutoFit Rows and Columns in Excel

AutoFit Multiple Rows and Columns in Excel in Python

To AutoFit multiple rows and columns within a cell range, you can use the CellRange.AutoFitRows() and CellRange.AutoFitColumns() methods. The following are the detailed steps.

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFroFmFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Get a specific cell range in the worksheet using Worksheet.Range[] property.
  • AutoFit the rows and columns in the cell range using CellRange.AutoFitRows() and CellRange.AutoFitColumns() methods.
  • Save the result file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create an object of the Workbook class
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")
 
# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get a specific cell range in the worksheet
range = sheet.Range["A1:E14"]
# Or get the used cell range in the worksheet
# range = sheet.AllocatedRange

# Automatically adjust the heights of all rows in the cell range
range.AutoFitRows()
# Automatically adjust the widths of all columns in the cell range
range.AutoFitColumns()
 
# Save the resulting file
workbook.SaveToFile("AutoFitMultipleRowsAndColumns.xlsx", ExcelVersion.Version2016)
workbook.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.

Python: Align Text in Word

2024-04-11 05:59:15 Written by support iceblue

Text alignment in Word refers to the way text is aligned along the horizontal axis of the page. Proper text alignment can significantly affect the overall appearance and aesthetics of a document, making it more engaging for readers. There are several types of text alignment available in Word:

  • Left Alignment: Text is aligned along the left margin.
  • Center Alignment: Text is centered between the left and right margins.
  • Right Alignment: Text is aligned along the right margin.
  • Justified Alignment: Text is aligned along both the left and right margins.
  • Distributed Alignment: Text is evenly distributed between the left and right margins.

In this article, you will learn how to set different text alignments for paragraphs in Word in Python using Spire.Doc for Python.

Install Spire.Doc for Python

This scenario requires Spire.Doc for Python and plum-dispatch v1.7.4. They can be easily installed in your VS Code through the following pip commands.

pip install Spire.Doc

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Doc for Python in VS Code

Align Text in Word in Python

With Spire.Doc for Python, you can get the paragraph formatting through the Paragraph.Format property, and then use the HorizontalAlignment property of the ParagraphFormat class to align text left/ right, center text, justify text, or distribute text in Word paragraphs. The following are the detailed steps:

  • Create a Document instance.
  • Add a section to the document using Document.AddSection() method.
  • Add a paragraph to the section using Section.AddParagraph() method, and then append text to the paragraph.
  • Get the paragraph formatting using Paragraph.Format property.
  • Set left/center/right/justified/distributed text alignment for the paragraph using ParagraphFormat.HorizontalAlignment property.
  • Save the result document using Document.SaveToFile() method.
  • Python
from spire.doc import *
from spire.doc.common import *

# Create a Document instance
document = Document()

# Add a section
sec = document.AddSection()

# Add a paragraph and make it left-aligned
para = sec.AddParagraph()
para.AppendText("This paragraph is left-aligned.")
para.Format.HorizontalAlignment = HorizontalAlignment.Left

# Add a paragraph and make it centered
para = sec.AddParagraph()
para.AppendText("This paragraph is centered.")
para.Format.HorizontalAlignment = HorizontalAlignment.Center

# Add a paragraph and make it right-aligned
para = sec.AddParagraph()
para.AppendText("This paragraph is right-aligned.")
para.Format.HorizontalAlignment = HorizontalAlignment.Right

# Add a paragraph and make it justified
para = sec.AddParagraph()
para.AppendText("This paragraph is justified.")
para.Format.HorizontalAlignment = HorizontalAlignment.Justify

# Add a paragraph and make it distributed
para = sec.AddParagraph()
para.AppendText("This paragraph is distributed.")
para.Format.HorizontalAlignment = HorizontalAlignment.Distribute

# Save the result file
document.SaveToFile("AlignText.docx", FileFormat.Docx)
document.Close()

Python: Align Text in Word

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.

Page 1 of 288