c# 如何打开和关闭Visio文件

豕怎么读2023-05-09  18

Visio Drawing Control控件使用
Visio开发必备
Visio SDK 2007
VisSDKchm
Visio Code Samples Librarychm
Visio文档操作
查看ShapeSheet属性及帮助内容
宏的录制
Visio的几个重要对象
Application
Window (ApplicationActiveWindow)
Document (ApplicationActiveDocument)
Master、Shape
Visio XML格式文件分析
Master格式
Pages/Shapes格式
图纸的XML文档中,Master后面的Shapes集合中只有一个Shape对象
图纸的Shapes集合有多个对象,每个对象的NameU和Name值可能不一样,一般使用NameU
Visio基本操作的实现
VisApplication = thisctrlDrawingDocumentApplication;
VisWindow = VisApplicationActiveWindow;
VisDocument = VisApplicationActiveDocument;
//Settings
VisApplicationSettingsShowShapeSearchPane = false; //显示搜索形状窗体
VisApplicationSettingsEnableAutoConnect = false; //自动链接(2007默认)
VisApplicationSettingsStencilBackgroundColor = 10070188; //vbGrayText
//文档各种显示
VisApplicationDoCmd((short)VisUICmdsvisCmdViewRulers);
VisApplicationDoCmd((short)VisUICmdsvisCmdViewGrid);
VisApplicationDoCmd((short)VisUICmdsShowGuides);
VisApplicationDoCmd((short)VisUICmdsShowConnectPoints);
VisApplicationDoCmd((short)VisUICmdsShowPageBreaks);
//各种窗口
VisApplicationDoCmd((short)VisUICmdsvisCmdShapesWindow);
VisApplicationDoCmd((short)VisUICmdsvisCmdPanZoom);
VisApplicationDoCmd((short)VisUICmdsvisCmdCustProp);
VisApplicationDoCmd((short)VisUICmdsvisCmdSizePos);
SendKeysSend("^(x)");
//VisApplicationDoCmd((short)VisUICmdsvisCmdUFEditCut);
SendKeysSend("{DELETE}");
//VisApplicationDoCmd((short)VisUICmdsvisCmdUFEditClear);
SendKeysSend("^+(p)");
//VisApplicationDoCmd(VisUICmdsvisCmdFormatPainter);
SendKeysSend("^(z)");
//VisApplicationDoCmd(VisUICmdsvisCmdEditUndo);
调用工具条对象、菜单对象的方法
ApplicationCommandBars
MicrosoftOfficeCoreCommandBars共享Office对象模型
使用CommandBar代替UIObject
CommandBar对象中,菜单及工具条是同一个东西
CommandBar、CommandBarButton、 CommandBarComboBox、CommandBarControl、 和 CommandBarPopup
示例:执行视图中的工具条的所有按钮事件。
MicrosoftOfficeCoreCommandBars commandBars;
commandBars = (MicrosoftOfficeCoreCommandBars)VisApplicationCommandBars;
foreach (MicrosoftOfficeCoreCommandBarControl control in commandBars["View"]Controls)
{
MicrosoftOfficeCoreCommandBarButton button = control as MicrosoftOfficeCoreCommandBarButton;
if (button != null)
{
buttonExecute();
}
}
StringBuilder sb = new StringBuilder();
foreach (MicrosoftOfficeCoreCommandBar bar in commandBars)
{
sbAppend(stringFormat("CommandBar Name:{0}\r\n", barName));
foreach(MicrosoftOfficeCoreCommandBarControl control in barControls)
{
MicrosoftOfficeCoreCommandBarButton button = control as MicrosoftOfficeCoreCommandBarButton;
if(button != null)
{
sbAppend(stringFormat("Button Name:{0} \r\n", buttonCaption));
}
}
}
Form2 frm = new Form2();
frmtxtContentText = sbToString();
frmShow();
short flags = (short)VisOpenSaveArgsvisOpenDocked | (short)VisOpenSaveArgsvisOpenRO;
StencilOpenEx(wndVisioApplication, flags);
///// <summary>
/// 打开模具的公共方法
/// </summary>
/// <param name="visApp">按引用调用的VisioApplication对象</param>
/// <param name="flags">打开的模式</param>
private void StencilOpenEx(Application visApp, short flags)
{
List<string>stencilList = GetStencils();
string stencilFileName;
foreach(string stencil in stencilList)
{
stencilFileName = GetStencilsFileName(stencil);
if(!stringIsNullOrEmpty(stencilFileName))
{
visAppDocumentsOpenEx(PortalgcgStencileFileBasePath + stencilFileName, flags);
}
}
}
//关闭模具文件
visAppDocuments["Switchvss"]Close();
visAppDocuments["Spanvss"]Close();
visAppDocuments["Linevss"]Close();
visAppDocuments["Labelvss"]Close();
visAppDocuments["Constructvss"]Close();
visAppDocuments["Monitorvss"]Close();
Visio Shape的属性操作
StringToFormulaForString、FormulaStringToString函数
访问属性
设置属性
添加属性
//列出模具组
thiscmbStencilGroupItemsClear();
List<string>stencilGroups = stencilGetStencils();
foreach (string group in stencilGroups)
{
thiscmbStencilGroupItemsAdd(group);
}
//根据模具组列出模具
string stencilName = stencilGetStencilsFileName(thiscmbStencilGroupText);
thiscmbStencilItemsClear();
string tempName;
foreach (Master master in visAppDocuments[stencilName]Masters)
{
tempName = masterName;
if (!stencilIsExcludeItem(tempName))
{
thiscmbStencilItemsAdd(tempName);
}
}
//根据模具,获取对应的属性集合,遍历属性集合,列出属性名称
string stencilName = stencilGetStencilsFileName(thiscmbStencilGroupText);
string masterName = thiscmbStencilText;
VisioShape shape = visAppDocuments[stencilName]Masters[masterName]Shapes[1];
if (shape != null)
{
List<StencilPropertyInfo>propInfos = propertyGetPropertyCollection(shape);
foreach (StencilPropertyInfo info in propInfos)
{
thiscmbPropertyItemsAdd(infoName);
}
}
//根据模具、模具属性,列出对应的属性信息
string stencilName = stencilGetStencilsFileName(thiscmbStencilGroupText);
string masterName = thiscmbStencilText;
VisioShape shape = visAppDocuments[stencilName]Masters[masterName]Shapes[1];
StencilPropertyInfo info = propertyGetProperty(shape, thiscmbPropertyText);
if (info != null)
{
thistxtNameText = infoName; //属性名称
thistxtValueText = infoValue; //属性值
thistxtFormatText = infoFormat; //属性格式
thistxtSortKeyText = infoSort; //属性的排序
thistxtPromptText = infoPrompt; //属性的提示信息
}
//根据模具,获取属性对象集合
public List<StencilPropertyInfo> GetPropertyCollection(VisioShape shape)
{
List<StencilPropertyInfo> list = new List<StencilPropertyInfo>();
StencilPropertyInfo propertyInfo;
VisioCell shapeCell;
short shortSectionProp = (short)VisSectionIndicesvisSectionProp;
if (shape != null)
{
for (short i = 0; i < shapeget_RowCount(shortSectionProp) - 1; i++ )
{
if (shapeget_CellsSRCExists(shortSectionProp, i, (short)VisCellIndicesvisCustPropsLabel, 0) != 0)
{
propertyInfo = new StencilPropertyInfo();
shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsLabel);
propertyInfoName = VisioUtilityFormulaStringToString(shapeCellRowNameU);
shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsPrompt);
propertyInfoPrompt = VisioUtilityFormulaStringToString(shapeCellFormulaU);
shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsFormat);
propertyInfoFormat = VisioUtilityFormulaStringToString(shapeCellFormulaU);
shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsValue);
propertyInfoValue = VisioUtilityFormulaStringToString(shapeCellFormulaU);
shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsSortKey);
propertyInfoSort = VisioUtilityFormulaStringToString(shapeCellFormulaU);
//shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsType);
//propertyInfoPropType = VisioUtilityFormulaStringToString(shapeCellFormulaU);
//shapeCell = shapeget_CellsSRC(shortSectionProp, i, (short)VisCellIndicesvisCustPropsInvis);
//propertyInfoInVisible = VisioUtilityFormulaStringToString(shapeCellFormulaU);
//
listAdd(propertyInfo);
}
}
}
return list;
}
//根据模具和属性名称,获取属性对象信息
public StencilPropertyInfo GetProperty(VisioShape shape, string propertyName)
{
List<StencilPropertyInfo> list = GetPropertyCollection(shape);
StencilPropertyInfo propertyInfo = null;
foreach(StencilPropertyInfo tempInfo in list)
{
if (tempInfoName == propertyName)
{
propertyInfo = tempInfo;
break;
}
}
return propertyInfo;
}
=====
我也没有写过visio操作,这个是收藏的代码,没有帮到你hoho,你可以去CSDN里面发帖求助一下

以上就是关于c# 如何打开和关闭Visio文件全部的内容,包括:c# 如何打开和关闭Visio文件、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

转载请注明原文地址:https://juke.outofmemory.cn/read/3854498.html

最新回复(0)