示例#1
0
        public List <IVisio.Shape> DrawDataTable(VisioScripting.TargetPage targetpage,
                                                 System.Data.DataTable datatable,
                                                 IList <double> widths,
                                                 IList <double> heights,
                                                 VisioAutomation.Geometry.Size cellspacing)
        {
            if (datatable == null)
            {
                throw new System.ArgumentNullException(nameof(datatable));
            }

            if (widths == null)
            {
                throw new System.ArgumentNullException(nameof(widths));
            }

            if (heights == null)
            {
                throw new System.ArgumentNullException(nameof(heights));
            }

            if (datatable.Rows.Count < 1)
            {
                throw new System.ArgumentOutOfRangeException(nameof(datatable), "DataTable must have at least one row");
            }

            targetpage = targetpage.ResolveToPage(this._client);
            string master             = "Rectangle";
            string stencil            = "basic_u.vss";
            var    stencildoc         = this._client.Document.OpenStencilDocument(stencil);
            var    stencildoc_masters = stencildoc.Masters;
            var    masterobj          = stencildoc_masters.ItemU[master];

            targetpage.Page.Background = 0; // ensure this is a foreground page

            var pagesize = VisioAutomation.Pages.PageHelper.GetSize(targetpage.Page);

            var layout = new GRID.GridLayout(datatable.Columns.Count, datatable.Rows.Count, new VisioAutomation.Geometry.Size(1, 1), masterobj);

            layout.Origin       = new VisioAutomation.Geometry.Point(0, pagesize.Height);
            layout.CellSpacing  = cellspacing;
            layout.RowDirection = GRID.RowDirection.TopToBottom;
            layout.PerformLayout();

            foreach (var i in Enumerable.Range(0, datatable.Rows.Count))
            {
                var row = datatable.Rows[i];

                for (int col_index = 0; col_index < row.ItemArray.Length; col_index++)
                {
                    var col       = row.ItemArray[col_index];
                    var cur_label = (col != null) ? col.ToString() : string.Empty;
                    var node      = layout.GetNode(col_index, i);
                    node.Text = cur_label;
                }
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawDataTable)))
            {
                layout.Render(targetpage.Page);
                targetpage.Page.ResizeToFitContents();
            }

            var shapes = layout.Nodes.Select(n => n.Shape).ToList();

            return(shapes);
        }
示例#2
0
        public List <IVisio.Shape> Table(System.Data.DataTable datatable,
                                         IList <double> widths,
                                         IList <double> heights,
                                         VisioAutomation.Geometry.Size cellspacing)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            if (datatable == null)
            {
                throw new System.ArgumentNullException(nameof(datatable));
            }

            if (widths == null)
            {
                throw new System.ArgumentNullException(nameof(widths));
            }

            if (heights == null)
            {
                throw new System.ArgumentNullException(nameof(heights));
            }

            if (datatable.Rows.Count < 1)
            {
                return(new List <IVisio.Shape>(0));
            }


            string master             = "Rectangle";
            string stencil            = "basic_u.vss";
            var    stencildoc         = this._client.Document.OpenStencil(stencil);
            var    stencildoc_masters = stencildoc.Masters;
            var    masterobj          = stencildoc_masters.ItemU[master];

            var app             = this._client.Application.Get();
            var application     = app;
            var active_document = application.ActiveDocument;
            var pages           = active_document.Pages;

            var page = pages.Add();

            page.Background = 0; // ensure this is a foreground page

            var pagesize = this._client.Page.GetSize();

            var layout = new GRID.GridLayout(datatable.Columns.Count, datatable.Rows.Count, new VisioAutomation.Geometry.Size(1, 1), masterobj);

            layout.Origin       = new VisioAutomation.Geometry.Point(0, pagesize.Height);
            layout.CellSpacing  = cellspacing;
            layout.RowDirection = GRID.RowDirection.TopToBottom;
            layout.PerformLayout();

            foreach (var i in Enumerable.Range(0, datatable.Rows.Count))
            {
                var row = datatable.Rows[i];

                for (int col_index = 0; col_index < row.ItemArray.Length; col_index++)
                {
                    var col       = row.ItemArray[col_index];
                    var cur_label = (col != null) ? col.ToString() : string.Empty;
                    var node      = layout.GetNode(col_index, i);
                    node.Text = cur_label;
                }
            }

            using (var undoscope = this._client.Application.NewUndoScope("Draw Table"))
            {
                layout.Render(page);
                page.ResizeToFitContents();
            }

            var page_shapes = page.Shapes;
            var shapes      = layout.Nodes.Select(n => n.Shape).ToList();

            return(shapes);
        }