• ASP.NET中Visio图形的控制与数据的动态显示


     1 需要添加对Microsoft Visio 11.0 Type Library的引用(COM组件)。代码如下:
     2      using Microsoft.Office.Interop.Visio;
     3 private void Button1_Click(object sender, System.EventArgs e)
     4          {
     5               Document doc=null;
     6               Cell cell=null;
     7               ApplicationClass app=new ApplicationClass();//运行Visio应用程序
     8               string CurrentPath=MapPath(".");
     9               doc=app.Documents.OpenEx(CurrentPath+"\\bin\\test2.vsd",(short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenCopy);//打开一个visio文件
    10               const string CUST_PROP_PREFIX = "Prop."; //自定义属性前缀
    11               try
    12               {   
    13                    for(int i=1;i<=doc.Pages[1].Shapes.Count;i++)
    14                    {
    15                         doc.Pages[1].Shapes[i].Rotate90();//将图形旋转90度
    16                        doc.Pages[1].Shapes[i].Text="hello";//设置图形的文本
    17                         if(doc.Pages[1].Shapes[i].get_CellExists("TagNum",(short)Microsoft.Office.Interop.Visio.VisExistsFlags.visExistsAnywhere)!=0)//检查定制是否存在指定定制属性
    18                        {
    19                             doc.Pages[1].Shapes[i].Text=data;//在此处显示图形数据
    20                        }
    21                    }
    22                    doc.Saved=true;//告诉Visio应用程序该文件已保存, 不然Visio要出现是否要保存的对话框,实际上并未保存,因为我们不想对源文件作修改,只是修改过后显示一下就行了。
    23                    doc.Pages [1].Export(CurrentPath+"\\test.jpg");//转换成jpg格式的文件
    24               }
    25               finally
    26               {
    27                    doc.Close();//关闭打开的文件
    28                    app.Quit();//退出Visio应用程序
    29               }
    30              
    31          }
    32     
    33 测试环境:
    34 Visio 2003+IIS 5.0+.NET FrameWork 1.1
    35 未解决的问题:
    36 1、  即使在一个形状中定义了自定义属性, 通过get_CellExists也无法检测到
    37 2、  不知如何通过代码改变形状的背景色
  • 相关阅读:
    using vb.net export a datatable to Excel and save as file
    selection sort with objective c
    stdin和STDIN_FILENO的区别
    stdin和STDIN_FILENO的区别
    linux系统kbhit的几种实现
    成为掌握企业聘用趋势的人才
    linux系统kbhit的几种实现
    c_lflag中ICANON的作用
    常量字符串的问题
    mmsbitfields gcc和vc关于位域那点事
  • 原文地址:https://www.cnblogs.com/wangguowen27/p/visio.html
Copyright © 2020-2023  润新知