问题描述
如果以前问过此问题,我们深表歉意,但在搜索一段时间后,我找不到任何具体的答案。
I apologize if this was asked before, but after searching for some time, I could not find any specific answer on this.
我在Visio中有一个ERD图它有大约15个表左右。为了让我们的DBA创建数据库,我必须输出每个列到数据类型,主键,描述的excel表。
I have an ERD diagram in Visio 2010. It has around 15 tables or so. In order to have our DBAs create the database, I have to output each column to excel sheet with the data type, primary key, description.
我的第一次尝试是简单地复制和粘贴列定义表从形状属性,但这不工作(感谢Microsoft!)。在尝试了几个其他事情后,结果是我必须手动复制每个表格的每个表 - 耗时。
My first attempt was to simply copy and paste the column definitions table from the shape properties, but this does not work (thanks Microsoft!). After trying a few other things, it turned out I would have to copy every cell manually for every table - time consuming.
我转向C#和Visio Interop的帮助。我现在可以导出列定义(它们在形状的Text属性中),但我找不到包含表名称的属性。
I turned to C# and Visio Interop for help. I am able to export the column definitions now (they are in Text property of the shape), but I can not find the property which holds the name of the table.
谢谢
推荐答案
最后我解决了。我无法解析出标准的Visio绘图(.vsd),所以我选择了Visio XML绘图(.vdx)。最后,这对我有用:
In the end I solved it. I was unable to parse out the standard Visio drawing (.vsd) so I opted for Visio XML Drawing (.vdx). In the end, this worked for me:
其中path是vxd绘图的文件路径。我发现,在XML绘图中的页面中的每个形状定义都有自己的2个形状。第一个形状保存实体名称,第二个保存实体列。
Where path is the file path to the vxd drawing. I turned out that each shape definition in the page in XML drawing has 2 shapes of its own. The first shape holds the Entity name, the second holds the Entity Columns.
XDocument xdoc = XDocument.Load(path);
var elements = xdoc.Elements().Elements();
XName pageXName = XName.Get("Page","http://schemas.microsoft.com/visio/2003/core");
var pages = elements.Elements(pageXName);
foreach (XElement page in pages)
{
XName shapeXName = XName.Get("Shape","http://schemas.microsoft.com/visio/2003/core");
var shapes = from shape in page.Elements().Elements(shapeXName)
where shape.Attribute("Type").Value == "Group"
select shape;
foreach (XElement shape in shapes)
{
var shapeShapes = shape.Elements();
List<XElement> textShapes = shapeShapes.Elements(shapeXName).ToList();
XName textXName = XName.Get("Text","http://schemas.microsoft.com/visio/2003/core");
XName cpXName = XName.Get("Text", "http://schemas.microsoft.com/visio/2003/core");
string tableName = textShapes[0].Elements(textXName).SingleOrDefault().Value;
string columns = textShapes[1].Elements(textXName).SingleOrDefault().Value;
Debug.WriteLine("-------------" + tableName.TrimEnd('\n') + "---------------");
Debug.Write(columns);
Debug.WriteLine("----------------------------");
}
}
这篇关于Visio 2010 C#实体自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!