利用Visio导出组织结构图

在做HR系统的时候,往往需要导出Visio格式的组织结构图。

以前很少接触Office的二次开发,这个东西足足搞了我一个礼拜,汗~~~~~

 

我的环境为Visio2003+VS2005

主要是利用OrgCWiz,这个Visio提供的接口,具体的参数请参考MS的网站

http://office.microsoft.com/zh-cn/visio/HA010774642052.aspx

个人认为http://visio.mvps.org/VBA.htm这个网站比较专业,很多关于Visio的资料可以参考一下

导出的代码很简单,主要为

Microsoft.Office.Interop.Visio.ApplicationClass   _app    =     new    ApplicationClass(); 

Microsoft.Office.Interop.Visio.Addon   ac   
=    _app.Addons.get_ItemU( " OrgCWiz " ); 

ac.Run(
" /S-INIT " ); 

string    commandargs    =     "  ............................... "

ac.Run(
" /S-ARGSTR    " + commandargs); 

ac.Run(
" /S-RUN " ); 

_app.ActiveDocument.SaveAsEx(destfile,
6 ); 

_app.Quit(); 

GC.Collect(); 

也可以参考http://www.cnblogs.com/invinboy/archive/2006/05/19/404725.html这篇文章

以下代码为设置文本框的背景色

Cell cell  =  shape.get_CellsSRC(( short )VisSectionIndices.visSectionObject,
                     (
short )VisRowIndices.visRowFill, ( short )VisCellIndices.visFillForegnd);
cell.FormulaU 
=   " RGB(176,197,227) " ;

以下代码为设置Title(字体大小及颜色)

Shape shapeTitle  =  page.Drop(doc.Masters.get_ItemU( " Title " ),  6 7.8 );
shapeTitle.Text 
=   "" ;
Cell cellTitle 
=  shapeTitle.get_CellsSRC(( short )VisSectionIndices.visSectionCharacter,
                 
0 , ( short )VisCellIndices.visCharacterColor);
cellTitle.FormulaU 
=   " RGB(153,0,51) " ;
shapeTitle.Characters.Text 
=    " 组织结构图 " ;
shapeTitle.Characters.set_CharProps(
                (
short )VisCellIndices.visCharacterStyle,
                (
short )VisCellVals.visBold);
shapeTitle.Characters.set_CharProps((
short )VisCellIndices.visCharacterSize,  24 );

以下代码为导出员工照片

Shape visShapeImage  =  shape.Import(filepath);
Cell vsoCell 
=  visShapeImage.get_Cells( " PinX " );
vsoCell.Formula 
=  shape.NameID  +   " !Width*0.3 " ;
vsoCell 
=  visShapeImage.get_Cells( " PinY " );
vsoCell.Formula 
=  shape.NameID  +   " !Height*0.5 " ;
vsoCell 
=  visShapeImage.get_Cells( " Width " );
vsoCell.Formula 
=  shape.NameID  +   " !Width*0.5 " ;
vsoCell 
=  visShapeImage.get_Cells( " Height " );
vsoCell.Formula 
=  shape.NameID  +   " !Height*0.5 " ;

// 设置user-defined cell属性
if  (shape.get_CellExists( " User.ShowPicture " 0 !=   0 )
{
    Cell showPicture 
= shape.get_CellsSRC((short)VisSectionIndices.visSectionUser,
        (
short)VisRowIndices.visRowUser + 2,
        (
short)VisCellIndices.visUserValue);
    showPicture.Formula 
= "1";
}


if  (shape.get_CellExists( " User.HasPicture " 0 !=   0 )
{
    Cell hasPicture 
= shape.get_CellsSRC((short)VisSectionIndices.visSectionUser,
        (
short)VisRowIndices.visRowUser + 10,
        (
short)VisCellIndices.visUserValue);
    hasPicture.Formula 
= "1";
}


if  (shape.get_CellExists( " User.PictureID " 0 !=   0 )
{
    Cell pictureID 
= shape.get_CellsSRC((short)VisSectionIndices.visSectionUser,
        (
short)VisRowIndices.visRowUser + 15,
        (
short)VisCellIndices.visUserValue);
    pictureID.Formula 
= """ + visShapeImage.NameID + """;
}

 

 

欢迎转载,请注明出处~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值