Ejemplo n.º 1
0
 /// <summary>
 /// Formats the to Page similar to the from page and 
 /// copies all from FromPage to ToPage
 /// </summary>
 /// <param name="fromPage">Source page</param>
 /// <param name="toPage">Destination page</param>
 private void CopyPage(Visio.Page fromPage, Visio.Page toPage)
 {
     SetupDestinationPage(fromPage, toPage);
     //Copy shapes
     fromPage.AddGuide((short)Visio.VisGuideTypes.visPoint, 0, 0);
     Visio.Selection selection = fromPage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll);
     selection.Copy();
     toPage.Paste();
     Visio.Selection resultSelection = toPage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll);
     double origX, origY, newX, newY, dummy1, dummy2;
     selection.BoundingBox(1, out origX, out origY, out dummy1, out dummy2);
     resultSelection.BoundingBox(1, out newX, out newY, out dummy1, out dummy2);
     double diffX = origX - newX;
     double diffY = origY - newY;
     resultSelection.Move(diffX, diffY);
 }
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            var app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException(nameof(src_page));
            }

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

            if (dest_page == src_page)
            {
                throw new AutomationException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new AutomationException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes=src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            var src_pagesheet = src_page.PageSheet;
            var pagecells = PageCells.GetCells(src_pagesheet);


            // handle the dest page

            // first update all the page cells
            var dest_pagesheet = dest_page.PageSheet;
            var update = new ShapeSheet.Update();
            update.SetFormulas(pagecells);
            update.Execute(dest_pagesheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;
            
            // then paste any contents from the first page
            if (num_src_shapes>0)
            {
                dest_page.Paste(copy_paste_flags);                
            }
        }