VISIO ユーザー会第 1 回セミナー VISIO 2007 VBA を利 した データの可視化 マイクロソフトディベロップメント株式会社オフィスグローバリゼーション開発統括部プログラムマネージャ 岸真 マイクロソフト株式会社 Visioグループテクノロジースペシャリスト 村佳代
アジェンダ Visio 2007 を利 した データの可視化 活 例 Visio 2007 データ接続オートメーション データの可視化 3ステップ
Visio 2007 データの可視化を実現する ビジネス ダイアグラム作成ツールとして進化 複雑な情報の理解を 深めるための 情報の可視化 傾向や問題を特定し 動を取るための 情報の把握 分析 幅広いユーザーと共有できる図 を使 した 情報の伝達
Visio 2007 を利 した データの可視化 活 例 Visio 図 連携データ先 業務フロー図 業務内容 進捗情報 担当者リスト コスト情報 病棟レイアウト図 病床管理 患者管理 ネットワーク図 機器情報 設定情報 リース情報 座席表 社員リスト 電話番号 メールアドレス フロア図 資産情報 什器
Visio 2007 データ接続オートメーション データソースと連動するソリューション開発のための API Data Import / Data Refresh API 図 に OLEDB/ODBC/XML データをインポート 更新 Data Linking API インポートしたデータと図形をリンク Data Graphics API リンクした図形でデータをグラフィック表
サンプルアプリケーションの作成 IT 資産情報の可視化 ネットワーク上のサーバーの状態を可視化し 現状の把握 分析をする簡易アプリケーションを VBA で開発します IP アドレス 稼働状況 管理者 ハードウェア情報ソフトウェア情報
データ接続の流れ DataRecordset と図形データフィールドをリンク Shape データグラフィックを適 して図形データを可視化 DataGraphic GraphicItem GraphicItem GraphicItem
データ接続の流れ 更新
ステップ 1 データのインポート 更新 オブジェクトとコンセプト インポートの 法と接続のモデル 更新と同期
オブジェクトとコンセプト Data Connection Visio からデータベースへの接続を抽象化 Data Recordset Visio 上のデータストアや データベースとの同期 アクセス 法を管理 Data Column データ形式やデータ型の変換機能
データのインポート接続モデル 接続する場合 接続しない場合 DataRecordsets.Add( string connectionstring, string commandstring, integer recordsetoptions, string friendlyname) DataRecordsets.AddFromXML( string adoxmlfragment, integer recordsetoptions, string friendlyname)
DataRecordsets.Add 外部データと Visio 図 を接続し インポート DataRecordsets.Add( string connectionstring, 接続 字列 string commandstring, コマンド 字列 integer recordsetoptions, オプション string friendlyname) 任意の表 名
Excel との接続 'Excel 接続 ' 接続 字列 コマンド 字列 DataRecordset オブジェクトを宣 Dim strconnection_excel As String Dim strcommand_excel As String Dim vsodatarecordset_excel As Visio.DataRecordset ' 接続 字列 ローカルドライブにあるファイルに接続 strconnection_excel = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" _ & "C: MSDN ASTMGT.XLS;" _ & "Extended Properties=Excel 8.0;" ' コマンド 字列 枚めのシート内のデータをすべて取得 strcommand_excel = "SELECT * FROM [Sheet1$]" 'DataRecordset オブジェクトを作成 Set vsodatarecordset_excel = ActiveDocument.DataRecordsets.Add(strConnection_Excel, strcommand_excel, 0, " ネットワーク機器 ")
Access との接続 'Access 接続 ' 接続 字列 コマンド 字列 DataRecordset オブジェクトを宣 Dim strconnection_access As String Dim strcommand_access As String Dim vsodatarecordset_access As Visio.DataRecordset ' 接続 字列 ローカルドライブにあるファイルに接続 パスワード等の設定は割愛 strconnection_access = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" _ & "C: MSDN network_status.mdb;" _ & "Persist Security Info=False; ' コマンド 字列 [ ネットワーク状態 ] テーブル内のデータをすべて取得 strcommand_access = "SELECT * FROM ネットワーク状態 " 'DataRecordset オブジェクトを作成 Set vsodatarecordset_access = ActiveDocument.DataRecordsets.Add(strConnection_Access, strcommand_access, 0, " ネットワーク状態 ")
ステップ 2 データのリンク 更新 オブジェクトとコンセプト リンクの 法
オブジェクトとコンセプト 1 リンク = 1 RowID 1 ShapeID RowID 1 42 2 27 3 12
リンクの 法 リンク図形の作成 法 : Page.DropLinked (1 1 図形 ) Page.DropManyLinkedU (n n 図形 ) 既存図形へのリンク 法 : Shape.LinkToData (1 1 図形 ) Selection.LinkToData (1 n 図形 ) Page.LinkShapesToDataRows (n n 図形 )
DropLinked 図 上にデータとリンクした図形をドロップ ( 作成 ) Page.DropLinked ( [Unknown] ObjectToDrop, double x, double y, Long DataRecordsetID, Visio オブジェクト x 座標 y 座標 DataRecordSet の ID Long DataRowID, データ の ID Booloean ApplyDataGraphicAfterLink) オプション
Excel データとリンクした図形を作成 'Visio 図形オブジェクト x 座標 y 座標 データ ID 格納 変数 等を宣 Dim vsoshape As Visio.Shape Dim dblx As Double Dim dbly As Double Dim lngdatarowid As Long Dim i As Integer Dim vsomaster As Visio.Master ' サーバー図形の ったステンシルを開く Set vsomaster = Visio.Documents.OpenEx("SERVER_M.vss", 4).ItemU("Server") '1 から 10 までのデータを図形にリンクして図 にドロップ For i = 1 To 10 dblx = dblx + 20 dbly = dbly + 15 lngrowid = i Set vsoshape = ActivePage.DropLinked(vsoMaster, _ dblx, _ dbly, _ vsodatarecordset_excel.id, _ lngrowid, _ False) Next i
AutomaticLink の値と図形のプロパティを 較判断して と図形を 動的にリンク Selection.AutomaticLink( (in) integer RecordsetID, (in) safe-array columnnames, (in) safe-array fieldtypes, (in) safe-array fieldnames, (in) bool BreakExistingLinks, (out) safe-array ShapeIDs) DataRecordSet の ID DataRecordset の列名図形側のフィールド図形側のフィールド名オプションリンクされた図形 ID 格納
Access データを 動リンク ' 図形の選択オブジェクト DataRecordset の列名 図形側のフィールドとフィールド名 リンクした図形を格納する配列を宣 Dim vsoselection As Visio.Selection Dim columnnames(1) As String Dim fieldtypes(1) As Long Dim fieldnames(1) As String Dim shapeslinked() As Long 'Access 側 (DataRecordset) の列名は [ ネットワーク名 ] columnnames(0) = " ネットワーク名 " ' 図形側は任意の図形データ fieldtypes(0) = Visio.VisAutoLinkFieldTypes.visAutoLinkCustPropsLabel ' 図形データのフィールド名は [ ネットワーク名 ] fieldnames(0) = " ネットワーク名 " ' 図 上の図形をすべて選択してオブジェクトに格納 ActiveWindow.DeselectAll ActiveWindow.SelectAll Set vsoselection = ActiveWindow.Selection ʻ 動リンク実 データグラフィックと連動しないようにオプションは 4 vsoselection.automaticlink vsodatarecordset_access.id, _ columnnames, _ fieldtypes, _ fieldnames, _ 4, _ shapeslinked
ステップ 3 データの表 更新 オブジェクトとコンセプト データグラフィックの作成と適
オブジェクトとコンセプト GraphicItem 図形 DataGraphic Master データのインポート データのリンク データの表示
オブジェクトとコンセプト DataGraphic Master GraphicItems コレクションのコンテナ GraphicItem 図形に追加された各データグラフィックオブジェクト データのインポート データのリンク データの表示
データグラフィックの作成 データグラフィックの作成は UI またはプログラムの両 で可能 法 1 Visio UI で : その 1: データグラフィックの設定画 で作成 本 はこちら その 2: データグラフィックマスタを シェイプシートで定義 法 2 プログラムで : DataGraphic Master オブジェクトを作成 GraphicItem プロパティを定義 データのインポート データのリンク データの表示
データグラフィックの適 ' 図 上の図形をすべて選択してオブジェクトの格納 Dim vsoselection As Visio.Selection ActiveWindow.SelectAll Set vsoselection = ActiveWindow.Selection ' 選択オブジェクトにデータグラフィックマスタを適 vsoselection.datagraphic = ActiveDocument.Masters(" トポロジ 1")
データの更新 3 種類の基本的な更新 法 refresh メソッド : DataRecordset.Refresh() DataRecordset.RefreshFromXML() 更新間隔を指定 : UI で : DataRecordset.RefreshInterval を設定 [ 更新 ] ボタン更新設定画 各更新内容はログからアクセス可能 : DataRecordsetChanged: イベント DataRecordsetChangedEvent: オブジェクト
データの更新 'Excel との同期を今すぐ実 Visio.ActiveDocument.DataRecordsets(1).Refresh 'Access との同期は 20 分ごと Visio.ActiveDocument.DataRecordsets(2).RefreshInterval = 20 今すぐ更新 20 分毎に更新
データ接続の流れ DataRecordset と図形データフィールドをリンク Shape データグラフィックを適 して図形データを可視化 DataGraphic GraphicItem GraphicItem GraphicItem
技術情報リソース -1- ダウンロード Visio 2007 SDK Visio 習書 http://www.microsoft.com/japan/office/2007/visio/trainingtext.mspx TechNet Visio 技術情報 http://www.microsoft.com/japan/technet/prodtechnol/visio/default.mspx オンラインリソース MSDN Visio 技術資料 http://www.microsoft.com/japan/msdn/office/understanding/visio.aspx Visio ブログ http://blogs.msdn.com/visioj/ Visio Tool box http://www.visiotoolbox.com/
技術情報リソース -2- その他 Visio.jp 書籍 http://www.visio.jp/ Visio 2003 デベロッパーズバイブル http://www.seshop.com/detail.asp?pid=6030
Visio 2007 製品体系 機能 データリンク データグラフィック機能 ピボットダイアグラム機能 新しいテンプレート (ITIL 図 バリューストリームマップ ) テンプレートのサンプル表 Standard の機能全て 主な 途専 的な作図システム管理 業務フロー 仕様書レイアウト図などデータと連携をした作図データと図 の 元管理情報の可視化と分析 機能 新した 作業の開始 画 オートコネクト機能テーマ機能隠し情報の削除 Web や PDF, XPS 形式での共有 主な 途図を含んだ 書作成企画書 提案書 組織図など
2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.