今天有空,下班前补齐解析visio图形形状的方法,包含图形背景色、字体颜色、备注信息、形状数据取值。

 /// <summary>
/// 设置形状的选择属性
/// </summary>
/******************************************************
* 0 仅选择组合形状。
* 1 首先选择组合形状
* 2 首先选择组合的组成部分
******************************************************/
public static void SetGroupSelectMode(Shape targetShape, int selectMode)
{
targetShape.get_CellsSRC((short)VisSectionIndices.visSectionObject, (short)VisRowIndices.visRowGroup,
(short)VisCellIndices.visGroupSelectMode).FormulaU = selectMode.ToString();
}

设置打开组合的器件,然后开始取数据:

               if (sp.Shapes.Count > )//组合类型
{
missDevice = false;
ShapeInfo spG = new ShapeInfo();
spG.Type = "器件";
spG.DeviceName = sp.Name.Split('.')[];
spG.DeviceDetail = "形状数据名:"+sp.Name+";";
addGroup(sp,spG); //拆分组合 SetGroupSelectMode(sp, );
spG.DeviceDetail += GetShapeCellProp(sp);
spG.Position = GetShaplocationInfo(sp);
spG.DeviceType = getTypeByBgColor(sp); if (spG.DeviceName != "")
{
visioInfoDic[PageName].Add(spG);
}
}
addGroup方法:
 private void addGroup(Shape sp,ShapeInfo spi)
{
foreach (Shape childSP in sp.Shapes)
{
/*线类型*/
if (childSP.Connects.Count > )
{
ShapeLine spL = new ShapeLine();
spL.LPosition = GetShaplocationInfo(sp); //位置信息
addLine(sp, spL, true);
spi.DeviceName = "";
visioLineDic[PageName].Add(spL);
break;
}
/*器件类型*/
ShapeInfo spchild = new ShapeInfo();
SetGroupSelectMode(childSP, );
if (childSP.Shapes.Count > )
addGroup(childSP, spi);
SetGroupSelectMode(childSP, ); /* 根据颜色判断*/
if(spi.DeviceType==null||spi.DeviceType=="")
spi.DeviceType = getTypeByBgColor(childSP);
if(childSP.Text.Contains("dB"))
getDWordColor(childSP,childSP.Text,spi); if (childSP.Text.Contains("F"))
{
spi.DeviceNum = childSP.Text.Split('/')[];
}
spchild.DeviceName = childSP.Text;
if (spchild.DeviceName != "")
{
spi.Label = (spi.Label == "") ? spchild.DeviceName : spi.Label + ";" + spchild.DeviceName;
}
} }
GetShapeCellProp读取形状数据的信息:
  /// <summary>
/// 获取图形属性
/// </summary>
private static string GetShapeCellProp(Shape shapeTarget)
{
string info = "";
for (int i = ; i < shapeTarget.get_RowCount((short)VisSectionIndices.visSectionProp); i++)
{
Cell cellKey = shapeTarget.get_CellsSRC((short)VisSectionIndices.visSectionProp, (short)i, (short));
Cell cellValue = shapeTarget.get_CellsSRC((short)VisSectionIndices.visSectionProp, (short)i, (short)VisCellIndices.visUserValue);
if (i > )
info += ";";
info += FormulaForString(cellKey.Formula) + ":" + FormulaForString(cellValue.Formula);
}
return info;
}
GetShaplocationInfo读取位置信息,前一篇已经给出。

获取文字颜色:
  if (sp.get_RowCount((short)VisSectionIndices.visSectionCharacter) == )
{
/*一个文本单个单颜色*/
Cell wordCell = sp.get_CellsSRC((short)VisSectionIndices.visSectionCharacter, , (short)VisCellIndices.visCharacterColor);
wordColor = wordCell.Formula;
deviceType(si, wordColor,power.Replace("/",""));
}
//多种颜色则循环取出
for (short i = ; i < sp.get_RowCount((short)VisSectionIndices.visSectionCharacter); i++)
{
Cell wordCells = sp.get_CellsSRC((short)VisSectionIndices.visSectionCharacter, i, (short)VisCellIndices.visCharacterColor);
if (wordCells.Formula.Contains("THEMEVAL()") && ((sp.get_RowCount((short)VisSectionIndices.visSectionCharacter) - ) == i))
{
break;
}
if (i > )
wordColor += "|";
wordColor += wordCells.Formula;
}

图形背景色:

Cell color = sp.get_CellsSRC((short)VisSectionIndices.visSectionObject, (short)VisRowIndices.visRowFill, (short)VisCellIndices.visFillForegnd);
string strColor = color.Formula;

  大多数据都可以通过像取背景色一样,将形状的属性取出,比如线段粗细、字体、字体大小等等,有兴趣的继续研究。

 
 
 

visio二次开发——图纸解析之形状的更多相关文章

  1. visio二次开发——图纸解析之线段

    多写博客,其实还是蛮好的习惯的,当初大学的时候导师就叫我写,但是就是懒,大学的时候,谁不是魔兽或者LOL呢,是吧,哈哈哈. 好了,接着上一篇visio二次开发——图纸解析,我继续写. 摘要: (转发请 ...

  2. visio二次开发——图纸解析

    (转发请注明来源:http://www.cnblogs.com/EminemJK/) visio二次开发的案例或者教程,国内真的非常少,这个项目也是花了不少时间来研究visio的相关知识,困难之所以难 ...

  3. C#进行Visio二次开发之文件导出及另存Web页面

    在我前面很多关于Visio的开发过程中,介绍了各种Visio的C#开发应用场景,包括对Visio的文档.模具文档.形状.属性数据.各种事件等相关的基础处理,以及Visio本身的整体项目应用,虽然时间过 ...

  4. visio二次开发初始化问题

    (转发请注明来源:http://www.cnblogs.com/EminemJK/) 问题: axDrawingControl1初始化失败((System.ComponentModel.ISuppor ...

  5. (5)微信二次开发 之 XML格式数据解析

    1.首先理解一下html html的全名是:HyperText Transfer markup language 超级文本标记语言,html本质上是一门标记(符合)语言,在html里,这些标记是事先定 ...

  6. java微信开发API解析(二)-获取消息和回复消息

    java微信开发API解析(二)-获取消息和回复消息 说明 * 本演示样例依据微信开发文档:http://mp.weixin.qq.com/wiki/home/index.html最新版(4/3/20 ...

  7. ECMALL模板解析机制.MVC架构分析及文件目录说明.二次开发指南手册(转)

    ECMALL模板解析语法与机制 http://www.nowamagic.net/architecture/archt_TemplateSyntaxAndAnalysis.php ECMALL模块开发 ...

  8. 解析大型.NET ERP系统 窗体、查询、报表二次开发

    详细介绍Enterprise Solution 二次开发的流程步骤,主要包括数据输入窗体(Entry Form),查询(Query/Enquiry),报表(Report)三个重要的二次开发项目. 数据 ...

  9. 转:二十一、详细解析Java中抽象类和接口的区别

    转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...

随机推荐

  1. JS和ASP.net相互调用问题

    项目开发时,我们有时候会遇到后台asp调用前台的JS函数,又或者前台JS需要调用后台aspx.cs的函数,这里记录下如何处理这些问题 1.  ASP后台代码中,如果需要运行JS函数,则使用Regist ...

  2. Linux系统用户和用户组介绍

    1.请问如下登录环境故障的原理及解决办法? [root@server test]# useradd rr ##创建用户rr [root@server test]# id rr uid=510(rr) ...

  3. nginx在linux下安装

    安装前先确认是否已经安装编译包和一些依赖包如果没有安装: yum install pcre* yum install openssl* yum install zlib yum install zli ...

  4. Web.xml配置详解

    (转自:http://www.cnblogs.com/chinafine/archive/2010/09/02/1815980.html) 1 定义头和根元素 部署描述符文件就像所有XML文件一样,必 ...

  5. ubuntu kylin 14.04安装Node.js和Famous

    默认使用软件中心安装node.js,然后参考https://famo.us/install进行安装 1.sudo apt-get install git 2.npm install -g yo gru ...

  6. apache 开机自启动脚本设置

    默认我们源码编译安装apache,是不能使用service这个命令来启动的,通常我们启动的命令是: [root@localhost httpd-2.2.16]# /usr/local/apache2/ ...

  7. ACCELEROMETER

    顾名思义,是加速感应器.有2种应用吧:1,电脑保护,例如当笔记本掉落时,可以被自动检测到,此时会自动关闭硬盘操作以保护数据不在强烈冲击时丢失.

  8. Linux 进程与线程五

    pthread_self函数 pthread_t pthread_self(void); 一般会成功,返回当前线程的ID 注意:在子线程中执行exit()函数会退出整个进程,一般使用pthread_e ...

  9. [LeetCode] Paint House II 粉刷房子之二

    There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...

  10. java之并发编程线程池的学习

    如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因为频繁创建线程和销毁线程需要时间. java.uitl.concurrent.Thre ...