代码之家  ›  专栏  ›  技术社区  ›  JohnGoldsmith

如何使用Python读取和写入Visio形状数据

  •  0
  • JohnGoldsmith  · 技术社区  · 6 年前

    检查Visio形状中的单元格时,以下代码不会返回预期值:

    costVal= shpObj1.CellsU("Prop.Cost")
    print (costVal) 
    

    [ .]

    1 回复  |  直到 6 年前
        1
  •  3
  •   JohnGoldsmith    6 年前

    要在Visio中获取ShapeSheet单元格的值,必须对该单元格的一个 Result properties .

    import os
    import win32com.client
    
    from win32com.client import constants
    
    # this sample assumes that Visio is running, that the ActiveWindow
    # is a Drawing window and that the Selection.PrimaryItem
    # is a 'Decision' shape from the 'Basic Flowchart Shapes' stencil
    
    # get the running app
    appVisio = win32com.client.GetActiveObject("Visio.Application")
    
    # selection gets you the 1 or more selected shapes and
    # the PrimaryItem returns the main / primary item in that selection
    # or null if the selection is empty
    targetShp = appVisio.ActiveWindow.Selection.PrimaryItem
    
    # set the cell
    targetShp.CellsU("Prop.Cost").FormulaU = "=2.50"
    
    # read the cell using its 'internal units' result property
    print(targetShp.CellsU("Prop.Cost").ResultIU)