Hello,
Thanks for your inquiry.
In Microsoft Word, the caption can only be placed above or below the image, and cannot be centered. Can you do this in Microsoft? To help us investigate further, cloud you please tell us the steps?
To ensure that you can insert Table of Figures in Word, please use the following code to test and verify whether it meets your needs.
- Code: Select all
from spire.doc import *
from spire.doc.common import *
# Create a Word document object
document = Document()
# Add a section
section = document.AddSection()
# Add a new paragraph and add an image to it
pictureParagraphCaption = section.AddParagraph()
pictureParagraphCaption.Format.AfterSpacing = 10
pic1 = pictureParagraphCaption.AppendPicture("AddImageCaption\\1.jpg")
pic1.Height = 100
pic1.Width = 100
# Add a caption to the image
format = CaptionNumberingFormat.Number
pic1.AddCaption("Figure", format, CaptionPosition.BelowItem)
# Add another new paragraph and add an image to it
pictureParagraphCaption = section.AddParagraph()
pic2 = pictureParagraphCaption.AppendPicture("AddImageCaption\\1.jpg")
pic2.Height = 100
pic2.Width = 100
# Add a caption to the image
pic2.AddCaption("Figure", format, CaptionPosition.BelowItem)
# Update all fields in the document
document.IsUpdateFields = True
# Save the document as a docx file
result = "output.docx"
document.SaveToFile(result, FileFormat.Docx2016)
# Close the document object and release resources
document.Close()
document.Dispose()
Sincerely,
Tommy
E-iceblue support team