当前位置: 首页>>代码示例>>C#>>正文


C# OPCPackage.GetPart方法代码示例

本文整理汇总了C#中NPOI.OpenXml4Net.OPC.OPCPackage.GetPart方法的典型用法代码示例。如果您正苦于以下问题:C# OPCPackage.GetPart方法的具体用法?C# OPCPackage.GetPart怎么用?C# OPCPackage.GetPart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.OpenXml4Net.OPC.OPCPackage的用法示例。


在下文中一共展示了OPCPackage.GetPart方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: POIXMLDocumentPart

        /**
         * Construct POIXMLDocumentPart representing a "core document" namespace part.
         */
        public POIXMLDocumentPart(OPCPackage pkg)
        {
            PackageRelationship coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).GetRelationship(0);

            this.packagePart = pkg.GetPart(coreRel);
            this.packageRel = coreRel;
        }
开发者ID:89sos98,项目名称:npoi,代码行数:10,代码来源:POIXMLDocumentPart.cs

示例2: Clone

        /**
         * Clone the specified namespace.
         *
         * @param   pkg   the namespace to clone
         * @param   file  the destination file
         * @return  the Cloned namespace
         */
        public static OPCPackage Clone(OPCPackage pkg, string path)
        {

            OPCPackage dest = OPCPackage.Create(path);
            PackageRelationshipCollection rels = pkg.Relationships;
            foreach (PackageRelationship rel in rels)
            {
                PackagePart part = pkg.GetPart(rel);
                PackagePart part_tgt;
                if (rel.RelationshipType.Equals(PackageRelationshipTypes.CORE_PROPERTIES))
                {
                    CopyProperties(pkg.GetPackageProperties(), dest.GetPackageProperties());
                    continue;
                }
                dest.AddRelationship(part.PartName, (TargetMode)rel.TargetMode, rel.RelationshipType);
                part_tgt = dest.CreatePart(part.PartName, part.ContentType);

                Stream out1 = part_tgt.GetOutputStream();
                IOUtils.Copy(part.GetInputStream(), out1);
                out1.Close();

                if (part.HasRelationships)
                {
                    Copy(pkg, part, dest, part_tgt);
                }
            }
            dest.Close();

            //the temp file will be deleted when JVM terminates
            //new File(path).deleteOnExit();
            return OPCPackage.Open(path);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:39,代码来源:PackageHelper.cs

示例3: GetTargetPart

 /**
  * Get the PackagePart that is the target of a relationship.
  *
  * @param rel The relationship
  * @param pkg The namespace to fetch from
  * @return The target part
  * @throws InvalidFormatException
  */
 protected static PackagePart GetTargetPart(OPCPackage pkg, PackageRelationship rel)
  {
     PackagePartName relName = PackagingUriHelper.CreatePartName(rel.TargetUri);
     PackagePart part = pkg.GetPart(relName);
     if (part == null) {
         throw new ArgumentException("No part found for relationship " + rel);
     }
     return part;
 }
开发者ID:hanwangkun,项目名称:npoi,代码行数:17,代码来源:POIXMLDocumentPart.cs

示例4: POIXMLProperties

        public POIXMLProperties(OPCPackage docPackage)
        {
            this.pkg = docPackage;

            // Core properties
            core = new CoreProperties((PackagePropertiesPart)pkg.GetPackageProperties());

            // Extended properties
            PackageRelationshipCollection extRel =
                pkg.GetRelationshipsByType(PackageRelationshipTypes.EXTENDED_PROPERTIES);
            if (extRel.Size == 1)
            {
                extPart = pkg.GetPart(extRel.GetRelationship(0));
                ExtendedPropertiesDocument props = ExtendedPropertiesDocument.Parse(
                     extPart.GetInputStream()
                );
                ext = new ExtendedProperties(props);
            }
            else
            {
                extPart = null;
                ext = new ExtendedProperties((ExtendedPropertiesDocument)NEW_EXT_INSTANCE.Copy());
            }

            // Custom properties
            PackageRelationshipCollection custRel =
                pkg.GetRelationshipsByType(PackageRelationshipTypes.CUSTOM_PROPERTIES);
            if (custRel.Size == 1)
            {
                custPart = pkg.GetPart(custRel.GetRelationship(0));
                CustomPropertiesDocument props = CustomPropertiesDocument.Parse(
                        custPart.GetInputStream()
                );
                cust = new CustomProperties(props);
            }
            else
            {
                custPart = null;
                cust = new CustomProperties((CustomPropertiesDocument)NEW_CUST_INSTANCE.Copy());
            }
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:41,代码来源:POIXMLProperties.cs

示例5: Assert_50154

        public void Assert_50154(OPCPackage pkg)
        {
            Uri drawingUri = new Uri("/xl/drawings/drawing1.xml",UriKind.Relative);
            PackagePart drawingPart = pkg.GetPart(PackagingUriHelper.CreatePartName(drawingUri));
            PackageRelationshipCollection drawingRels = drawingPart.Relationships;

            Assert.AreEqual(6, drawingRels.Size);

            // expected one image
            Assert.AreEqual(1, drawingPart.GetRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image").Size);
            // and three hyperlinks
            Assert.AreEqual(5, drawingPart.GetRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink").Size);

            PackageRelationship rId1 = drawingPart.GetRelationship("rId1");
            Uri parent = drawingPart.PartName.URI;
            Uri rel1 = new Uri(Path.Combine(parent.ToString(),rId1.TargetUri.ToString()),UriKind.Relative);
            Uri rel11 = PackagingUriHelper.RelativizeUri(drawingPart.PartName.URI, rId1.TargetUri);
            Assert.AreEqual("#'Another Sheet'!A1", HttpUtility.UrlDecode(rel1.ToString().Split(new char[]{'/'})[3]));

            PackageRelationship rId2 = drawingPart.GetRelationship("rId2");
            Uri rel2 = PackagingUriHelper.RelativizeUri(drawingPart.PartName.URI, rId2.TargetUri);
            Assert.AreEqual("../media/image1.png", rel2.OriginalString);

            PackageRelationship rId3 = drawingPart.GetRelationship("rId3");
            Uri rel3 = new Uri(Path.Combine(parent.ToString(), rId3.TargetUri.ToString()), UriKind.Relative);
            Assert.AreEqual("#ThirdSheet!A1", rel3.OriginalString.Split(new char[] { '/' })[3]);

            PackageRelationship rId4 = drawingPart.GetRelationship("rId4");
            Uri rel4 = new Uri(Path.Combine(parent.ToString(), rId4.TargetUri.ToString()), UriKind.Relative);
            Assert.AreEqual("#'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A1",HttpUtility.UrlDecode(rel4.OriginalString.Split(new char[] { '/' })[3]));

            //PackageRelationship rId5 = drawingPart.GetRelationship("rId5");
            //Uri rel5 = new Uri(Path.Combine(parent.ToString(), rId5.TargetUri.ToString()), UriKind.Relative);
            //// back slashed have been Replaced with forward
            //Assert.AreEqual("file:///D:/chan-chan.mp3", rel5.ToString());

            //PackageRelationship rId6 = drawingPart.GetRelationship("rId6");
            //Uri rel6 = new Uri(ResolveRelativePath(parent.ToString(), HttpUtility.UrlDecode(rId6.TargetUri.ToString())), UriKind.Relative);
            //Assert.AreEqual("../../../../../../../cygwin/home/yegor/dinom/&&&[access].2010-10-26.log", rel6.OriginalString);
            //Assert.AreEqual("#'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A5", HttpUtility.UrlDecode(rel6.OriginalString.Split(new char[] { '/' })[3]));
        }
开发者ID:89sos98,项目名称:npoi,代码行数:41,代码来源:TestRelationships.cs

示例6: Copy

        /**
         * Recursively copy namespace parts to the destination namespace
         */
        private static void Copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, PackagePart part_tgt) {
        PackageRelationshipCollection rels = part.Relationships;
        if(rels != null) 
            foreach (PackageRelationship rel in rels) {
            PackagePart p;
            if(rel.TargetMode == TargetMode.External){
                part_tgt.AddExternalRelationship(rel.TargetUri.ToString(), rel.RelationshipType, rel.Id);
                //external relations don't have associated namespace parts
                continue;
            }
            Uri uri = rel.TargetUri;

            if(uri.Fragment != null) {
                part_tgt.AddRelationship(uri, (TargetMode)rel.TargetMode, rel.RelationshipType, rel.Id);
                continue;
            }
            PackagePartName relName = PackagingUriHelper.CreatePartName(rel.TargetUri);
            p = pkg.GetPart(relName);
            part_tgt.AddRelationship(p.PartName, (TargetMode)rel.TargetMode, rel.RelationshipType, rel.Id);




            PackagePart dest;
            if(!tgt.ContainPart(p.PartName)){
                dest = tgt.CreatePart(p.PartName, p.ContentType);
                Stream out1 = dest.GetOutputStream();
                IOUtils.Copy(p.GetInputStream(), out1);
                out1.Close();
                Copy(pkg, p, tgt, dest);
            }
        }
    }
开发者ID:89sos98,项目名称:npoi,代码行数:36,代码来源:PackageHelper.cs

示例7: POIXMLDocumentPart

 /**
  * Construct POIXMLDocumentPart representing a "core document" namespace part.
  */
 public POIXMLDocumentPart(OPCPackage pkg)
 {
     PackageRelationship coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).GetRelationship(0);
     if (coreRel == null)
     {
         coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).GetRelationship(0);
         if (coreRel != null)
         {
             throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
         }
     }
     if (coreRel == null)
     {
         throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
     }
     this.packagePart = pkg.GetPart(coreRel);
     this.packageRel = coreRel;
 }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:21,代码来源:POIXMLDocumentPart.cs

示例8: assertMSCompatibility

        private void assertMSCompatibility(OPCPackage pkg)
        {
            PackagePartName relName = PackagingUriHelper.CreatePartName(PackageRelationship.ContainerPartRelationship);
            PackagePart relPart = pkg.GetPart(relName);

            XmlDocument xmlRelationshipsDoc = DocumentHelper.LoadDocument(relPart.GetInputStream());

            XmlElement root = xmlRelationshipsDoc.DocumentElement;
            XmlNodeList nodeList = root.GetElementsByTagName(PackageRelationship.RELATIONSHIP_TAG_NAME);
            int nodeCount = nodeList.Count;
            for (int i = 0; i < nodeCount; i++)
            {
                XmlElement element = (XmlElement)nodeList.Item(i);
                String value = element.GetAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME);
                Assert.IsTrue(value[0] != '/', "Root target must not start with a leading slash ('/'): " + value);
            }

        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:18,代码来源:TestPackage.cs


注:本文中的NPOI.OpenXml4Net.OPC.OPCPackage.GetPart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。