我正在尝试使用 Visio 2010 COM Interops 以编程方式创建时间线和标记。我的代码基于 Chris Castillo 的 2 部分博客文章(第 1部分、第 2 部分),这是我能够找到的关于如何执行此操作的唯一半完整示例。然而,他的博客(从 2004 年开始)似乎无法正常工作。里程碑并没有真正连接到时间线,更新它们的日期并不能让它们移动到正确的位置。
有什么建议或修复吗?
Imports Microsoft.Office.Interop.Visio
Imports System.Diagnostics.CodeAnalysis
Imports System.Runtime.InteropServices
...
Dim VisioApp As New Application
Dim myDoc As Document = VisioApp.Documents.Add("")
Dim myPage As Page = myDoc.Pages.Item(1)
Dim TimelineStencils As Document =
VisioApp.Documents.Add("Timeline Shapes.vss")
Dim theTimeline As Shape
Dim theMilestone As Shape
VisioApp.AlertResponse = 1
theTimeline = myPage.Drop(
TimelineStencils.Masters.ItemU("Block timeline"), 5.610236, 5.511811)
theTimeline.CellsU("User.visBeginDate").FormulaU = _
VisioApp.ConvertResult(
"1/1/2004", VisUnitCodes.visDate, VisUnitCodes.visInches)
theTimeline.CellsU("User.visEndDate").FormulaU = _
VisioApp.ConvertResult(
"12/31/2004", VisUnitCodes.visDate, VisUnitCodes.visInches)
VisioApp.Addons("ts").Run("/cmd=3")
theMilestone = myPage.Drop( _
TimelineStencils.Masters.ItemU("Line milestone"), _
5.610236, 5.511811)
theMilestone.CellsU("User.visMilestoneDate").FormulaU = _
VisioApp.ConvertResult(
"7/1/2004", VisUnitCodes.visDate, VisUnitCodes.visInches)
VisioApp.AlertResponse = 0