Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I add style to images? #1510

Open
@fyy623

Description

Basically, I want to achieve "Format Picture" in Office Word, where you right click an element in a .docx file and attach solid line (ideally, I want to also manually set color, width, transparency, etc) border to the image

import docx
from docx import Document
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
doc = Document(p)
for element in doc.element.body:
 if hasattr(element, 'inner_content_elements'):
 for ele in element.inner_content_elements:
 for i in ele.inner_content_items:
 outline = OxmlElement('a:ln', {'w': '9525'})
 solid_fill = OxmlElement('a:solidFill')
 scheme_color = OxmlElement('a:schemeClr', {'val': 'green'})
 solid_fill.append(scheme_color)
 outline.append(solid_fill)
 i.append(outline)

Above is the code I tried, which gives no error, but the result file is broken, as it says when I tried to open the file:

Word experienced an error trying to open the file. 
Try these suggestions.
* Check the file permissions for the document or drive.
* Make sure there is sufficient free memory and disk space.
* Open the file with the Text Recovery converter.
(Path/to/the/file)

Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /