コード例 #1
0
        public List <int> AddHyperlink(TargetShapes targetshapes, HyperlinkCells hlink)
        {
            if (hlink == null)
            {
                throw new System.ArgumentNullException(nameof(hlink));
            }

            targetshapes = targetshapes.ResolveToShapes(this._client);

            if (targetshapes.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            var hyperlink_indices = new List <int>();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddHyperlink)))
            {
                foreach (var shape in targetshapes.Shapes)
                {
                    int hi = HyperlinkHelper.Add(shape, hlink);
                    hyperlink_indices.Add(hi);
                }
            }

            return(hyperlink_indices);
        }
コード例 #2
0
        public List <int> Add(TargetShapes targets, HyperlinkCells ctrl)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            var hyperlink_indices = new List <int>();

            using (var undoscope = this._client.Application.NewUndoScope("Add Control"))
            {
                foreach (var shape in targets.Shapes)
                {
                    int hi = HyperlinkHelper.Add(shape, ctrl);
                    hyperlink_indices.Add(hi);
                }
            }

            return(hyperlink_indices);
        }
コード例 #3
0
        public void Hyperlinks_AddRemove()
        {
            var page1 = this.GetNewPage();

            var s1 = page1.DrawRectangle(0, 0, 4, 1);

            // Ensure we start with 0 hyperlinks
            Assert.AreEqual(0, HyperlinkHelper.GetCount(s1));

            // Add the first hyperlink

            var h1 = new HyperlinkCells();

            h1.Address = "http://microsoft.com";
            int h1_row = HyperlinkHelper.Add(s1, h1);

            Assert.AreEqual(1, HyperlinkHelper.GetCount(s1));

            // Add the second control
            var h2 = new HyperlinkCells();

            h2.Address = "http://google.com";
            int h2_row = HyperlinkHelper.Add(s1, h2);

            Assert.AreEqual(2, HyperlinkHelper.GetCount(s1));

            // retrieve the control information
            var hlinks = HyperlinkCells.GetCells(s1);

            // verify that the hyperlinks were set propery
            Assert.AreEqual(2, hlinks.Count);
            Assert.AreEqual("\"http://microsoft.com\"", hlinks[0].Address.Formula);
            Assert.AreEqual("\"http://google.com\"", hlinks[1].Address.Formula);

            // Delete both hyperlinks
            HyperlinkHelper.Delete(s1, 0);
            Assert.AreEqual(1, HyperlinkHelper.GetCount(s1));
            HyperlinkHelper.Delete(s1, 0);
            Assert.AreEqual(0, HyperlinkHelper.GetCount(s1));

            page1.Delete(0);
        }