eiceblue / Spire.Doc-for-Python

A professional Word Python API specifically designed for developers to create, read, write, convert, and compare Word documents with fast and high-quality performance.
8 stars 4 forks source link

TextBox.Format.NoLine not working #1

Open tehwenyi opened 7 months ago

tehwenyi commented 7 months ago

Hi, I'm having an issue removing the text box using textbox.Format.NoLine. Below is the code I tried:

from spire.doc import *
from spire.doc.common import *

# Create a Document object
document = Document()

document.LoadFromFile("/data/empty.docx")

# Insert a textbox and set its wrapping style
textBox = document.Sections[0].Paragraphs[0].AppendTextBox(135, 300)
textBox.Format.TextWrappingStyle = TextWrappingStyle.Square

# Set the position of the textbox
textBox.Format.HorizontalOrigin = HorizontalOrigin.RightMarginArea
textBox.Format.HorizontalPosition = -145.0
textBox.Format.VerticalOrigin = VerticalOrigin.Page
textBox.Format.VerticalPosition = 120.0

# Set the border style and fill color of the textbox
textBox.Format.NoLine = False
textBox.Format.FillColor = Color.get_LightGray()

# Insert an image to textbox as a paragraph
para = textBox.Body.AddParagraph();
picture = para.AppendPicture("C:/Users/Administrator/Desktop/Wikipedia_Logo.png")

# Set alignment for the paragraph
para.Format.HorizontalAlignment = HorizontalAlignment.Center

# Set the size of the inserted image
picture.Height = 90.0
picture.Width = 90.0

# Insert text to textbox as the second paragraph
textRange = para.AppendText("Wikipedia is a free encyclopedia, written collaboratively by the people who use it. "
    + "Since 2001, it has grown rapidly to become the world's largest reference website,  "
    + "with 6.7 million articles in English attracting billions of views every month.")

# Set alignment for the paragraph
para.Format.HorizontalAlignment = HorizontalAlignment.Center

# Set the font of the text
textRange.CharacterFormat.FontName = "Times New Roman"
textRange.CharacterFormat.FontSize = 12.0
textRange.CharacterFormat.Italic = True

# Save the result file
document.SaveToFile("/data/output/AddTextBox.docx", FileFormat.Docx)

Error message:

Traceback (most recent call last):
  File "/src/temp2.py", line 20, in <module>
    textBox.Format.NoLine = False
  File "/usr/local/lib/python3.10/dist-packages/spire/doc/TextBoxFormat.py", line 157, in NoLine
    CallCFunction(GetDllLibDoc().TextBoxFormat_set_NoLine,self.Ptr, value)
  File "/usr/local/lib/python3.10/dist-packages/spire/doc/common/__init__.py", line 105, in CallCFunction
    result = func(*args, **kwargs)
RuntimeError: ffi_prep_cif_var failed

I've attached the document "empty.docx" here as well. I installed Spire.Doc in my Docker container using pip install spire.doc.

[empty.docx](https://github.com/eiceblue/Spire.Doc-for-Python/files/14863905/empty.docx)

May I know how else I should remove the lines from textboxes? Thank you!

tehwenyi commented 7 months ago

To update, I solved this issue by downgrading to spire.doc==11.10.0