python pptx模块add_picture中的未知错误

时间:2016-07-19 14:54:21

标签: python python-pptx

我一直在尝试在powerpoint演示文稿的每张幻灯片上输入一系列图片。我输入图像路径和相关尺寸,但是我得到一个我不理解的错误。

    for k in xrange(0, len(prs.slides)):
        img_path = os_path + str(k+1) + '.png'
        left = Cm(1.21)
        top = Cm(4.72)
        width = Cm(5)
        height = Cm(5)
        pic = prs.slides[k].shapes.add_picture(img_path, left, top, width, height)

然后会出现此错误:

  File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:116494)
  File "src/lxml/parser.pxi", line 1700, in lxml.etree._parseDoc (src\lxml\lxml.etree.c:115040)
  File "src/lxml/parser.pxi", line 1040, in lxml.etree._BaseParser._parseUnicodeDoc (src\lxml\lxml.etree.c:109165)
  File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\lxml.etree.c:103404)
  File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src\lxml\lxml.etree.c:105058)
  File "src/lxml/parser.pxi", line 613, in lxml.etree._raiseParseError (src\lxml\lxml.etree.c:103967)
  lxml.etree.XMLSyntaxError: EntityRef: expecting ';', line 3, column 31

肯定有一个与img_path对应的文件,所以我不确定还有什么问题

1 个答案:

答案 0 :(得分:1)

我想我已修好了。

我的文档中的img_path包括&在文件名中 - 我更改了图像所在的位置(更改为没有&的文件夹)并且它有效。