public static void GetFormulasEx(this Visio.IVPage page, Int16[] sID_SRCStream, out object[] formulaArray)
        {
            formulaArray = null;

            Array arg1 = sID_SRCStream as Array;

            if (null == arg1)
            {
                arg1 = new Array[0];
            }

            IVPageVTable proxy = page.UnderlyingObject as IVPageVTable;

            if (null != proxy)
            {
                Array formulas = null;
                proxy.GetFormulas(ref arg1, out formulas);
                if (null != formulas)
                {
                    formulaArray = new object[formulas.Length];
                    for (int i = 0; i < formulas.Length; i++)
                    {
                        formulaArray[i] = formulas.GetValue(i);
                    }
                }
            }
            else
            {
                throw new InvalidCastException("Unable to cast underlying proxy into interop interface");
            }
        }
Exemple #2
0
        //CONNECT TO SHAPES
        public static Visio.IVShape CreateVisioShape(Visio.Application vApp, Visio.IVDocument drawingDocuemnt, double X_in, double Y_in, string stencilName, string masterNameU)
        {
            // Find the stencil in the Documents collection by name.
            Visio.IVDocuments visioDocuments = vApp.Documents;
            Visio.IVShape     droppedShape   = null;
            Visio.IVMaster    masterInStencil;

            Visio.IVPage page = drawingDocuemnt.Pages.First();

            //get width and height of the sheet
            double Sheet_Width  = page.PageSheet.get_CellsU("PageWidth").ResultIU;
            double Sheet_Height = page.PageSheet.get_CellsU("PageHeight").ResultIU;

            Sheet_Width  = Sheet_Width - 3;
            Sheet_Height = Sheet_Height - 3;

            Visio.IVDocument stencil;
            try
            {
                stencil = visioDocuments[stencilName];
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                // The stencil is not in the collection; open it as a
                // docked stencil.
                stencil = visioDocuments.OpenEx(stencilName, (short)VisOpenSaveArgs.visOpenDocked);
            }

            // Get a master from the stencil by its universal name.
            try
            {
                masterInStencil = stencil.Masters.get_ItemU(masterNameU);
                double actual_xposition = (Sheet_Width * X_in) + 2;
                double actual_yposition = (Sheet_Height * Y_in) + 2;
                droppedShape = page.Drop(masterInStencil, actual_xposition, actual_yposition);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Cannot create Visio shape. Error is : {0} {1}", Ex.Message, Ex.InnerException?.Message), "Visio interface error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            return(droppedShape);
        }
Exemple #3
0
        public Form1()
        {
            InitializeComponent();

            Visio.Application application = new Visio.Application();
            application.Visible = true;
            var doc = application.Documents.Add("");

            Visio.IVPage page  = application.ActivePage;
            var          shape = page.DrawRectangle(0, 0, 2, 3);

            shape.Text = "With Microsoft.Office.Interop.Visio";
            doc.Saved  = true;

            var SID_SRCStream = new short[4];

            SID_SRCStream[0] = (short)shape.ID16;
            SID_SRCStream[1] = (short)VisSectionIndices.visSectionObject;
            SID_SRCStream[2] = (short)VisRowIndices.visRowFill;
            SID_SRCStream[3] = (short)VisCellIndices.visFillForegnd;

            try
            {
                object[] a = null;// new Array[4];
                page.GetFormulasTest(SID_SRCStream, out a);

                // page.GetFormulas(SID_SRCStream, out a);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
            try
            {
                application.Quit();
                application.Dispose();
            }
            catch
            {
                // may closed by user
            }
        }