예제 #1
0
        public void TestTrailingSpacesInURI_53282()
        {
            OPCPackage pkg = null;

            using (Stream stream = OpenXml4NetTestDataSamples.OpenSampleStream("53282.xlsx"))
            {
                pkg = OPCPackage.Open(stream);
            }

            PackageRelationshipCollection sheetRels = pkg.GetPartsByName(new Regex("/xl/worksheets/sheet1.xml"))[0].Relationships;

            Assert.AreEqual(3, sheetRels.Size);
            PackageRelationship rId1 = sheetRels.GetRelationshipByID("rId1");

            Assert.AreEqual(TargetMode.External, rId1.TargetMode);
            Uri targetUri = rId1.TargetUri;

            Assert.AreEqual("mailto:[email protected]%C2%A0", targetUri.OriginalString);
            Assert.AreEqual("[email protected]\u00A0", targetUri.Scheme);

            MemoryStream out1 = new MemoryStream();

            pkg.Save(out1);


            pkg = OPCPackage.Open(new ByteArrayInputStream(out1.ToArray()));
            out1.Close();
            sheetRels = pkg.GetPartsByName(new Regex("/xl/worksheets/sheet1.xml"))[(0)].Relationships;
            Assert.AreEqual(3, sheetRels.Size);
            rId1 = sheetRels.GetRelationshipByID("rId1");
            Assert.AreEqual(TargetMode.External, rId1.TargetMode);
            targetUri = rId1.TargetUri;
            Assert.AreEqual("mailto:[email protected]%C2%A0", targetUri.OriginalString);
            Assert.AreEqual("[email protected]\u00A0", targetUri.Scheme);
        }
예제 #2
0
        public void TestFetchFromCollection()
        {
            Stream      is1   = OpenXml4NetTestDataSamples.OpenSampleStream("ExcelWithHyperlinks.xlsx");
            OPCPackage  pkg   = OPCPackage.Open(is1);
            PackagePart sheet = pkg.GetPart(
                PackagingUriHelper.CreatePartName(SHEET_WITH_COMMENTS));

            Assert.IsNotNull(sheet);

            Assert.IsTrue(sheet.HasRelationships);
            Assert.AreEqual(6, sheet.Relationships.Size);

            // Should have three hyperlinks, and one comment
            PackageRelationshipCollection hyperlinks =
                sheet.GetRelationshipsByType(HYPERLINK_REL_TYPE);
            PackageRelationshipCollection comments =
                sheet.GetRelationshipsByType(COMMENTS_REL_TYPE);

            Assert.AreEqual(3, hyperlinks.Size);
            Assert.AreEqual(1, comments.Size);

            // Check we can Get bits out by id
            // Hyperlinks are rId1, rId2 and rId3
            // Comment is rId6
            Assert.IsNotNull(hyperlinks.GetRelationshipByID("rId1"));
            Assert.IsNotNull(hyperlinks.GetRelationshipByID("rId2"));
            Assert.IsNotNull(hyperlinks.GetRelationshipByID("rId3"));
            Assert.IsNull(hyperlinks.GetRelationshipByID("rId6"));

            Assert.IsNull(comments.GetRelationshipByID("rId1"));
            Assert.IsNull(comments.GetRelationshipByID("rId2"));
            Assert.IsNull(comments.GetRelationshipByID("rId3"));
            Assert.IsNotNull(comments.GetRelationshipByID("rId6"));

            Assert.IsNotNull(sheet.GetRelationship("rId1"));
            Assert.IsNotNull(sheet.GetRelationship("rId2"));
            Assert.IsNotNull(sheet.GetRelationship("rId3"));
            Assert.IsNotNull(sheet.GetRelationship("rId6"));
        }