【问题标题】:Is there anyway to import an image into a Visio document using python?无论如何使用 python 将图像导入 Visio 文档?
【发布时间】:2019-06-05 22:03:05
【问题描述】:

我正在使用 pywin32 自动操作 Visio 文件。有没有办法使用 pywin32 或其他库将图像嵌入到 Visio 文档中?我还没有找到任何关于此的文档。

我知道创建新 Visio 文档的代码如下所示:

import win32com.client as win32
visio = win32.Dispatch("Visio.Application")
doc = visio.Documents.Add("Basic Diagram.vst")
doc.SaveAs("C:\\Users\\"username"\\Desktop\\test.vsdx")

但我不知道从这里去哪里。

任何建议将不胜感激。

【问题讨论】:

    标签: python visio pywin32


    【解决方案1】:

    这是对here上代码的Python修改:

    def dropImage(vPag, imageFile):
        if vPag is not None:
            shpNew = vPag.Import(imageFile)
            #Set position
            shpNew.CellsU("PinX").FormulaU = "75mm"
            shpNew.CellsU("PinY").FormulaU = "175mm"
            #Set size
            shpNew.CellsU("Width").FormulaU = "100mm"
            shpNew.CellsU("Height").FormulaU = "80mm"
    
    targetPage = appVisio.ActivePage
    
    dropImage(targetPage, r"C:\SomeImage.jpg") 
    

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多