using Microsoft.Office.Interop.Visio;
private void Button1_Click(object sender, System.EventArgs e)
{
Document doc=null;
Cell cell=null;
ApplicationClass app=new ApplicationClass();//运行Visio应用程序
string CurrentPath=MapPath(".");
doc=app.Documents.OpenEx(CurrentPath+"\\bin\\test2.vsd",(short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenCopy);//打开一个visio文件
const string CUST_PROP_PREFIX = "Prop."; //自定义属性前缀
try
{
for(int i=1;i<=doc.Pages[1].Shapes.Count;i++)
{
doc.Pages[1].Shapes.Rotate90();//将图形旋转90度
doc.Pages[1].Shapes.Text="hello";//设置图形的文本
if(doc.Pages[1].Shapes.get_CellExists("TagNum",(short)Microsoft.Office.Interop.Visio.VisExistsFlags.visExistsAnywhere)!=0)//检查定制是否存在指定定制属性
{
doc.Pages[1].Shapes.Text=data;//在此处显示图形数据
}
}
doc.Saved=true;//告诉Visio应用程序该文件已保存, 不然Visio要出现是否要保存的对话框,实际上并未保存,因为我们不想对源文件作修改,只是修改过后显示一下就行了。
doc.Pages [1].Export(CurrentPath+"\\test.jpg");//转换成jpg格式的文件
}
finally
{
doc.Close();//关闭打开的文件
app.Quit();//退出Visio应用程序
}
}