Ejemplo n.º 1
0
        /**
         * Ensure that a memory based package part does not have lingering data from previous
         * commit() calls.
         *
         * Note: This is overwritten for some objects, as *PictureData seem to store the actual content
         * in the part directly without keeping a copy like all others therefore we need to handle them differently.
         */
        protected internal virtual void PrepareForCommit()
        {
            PackagePart part = this.GetPackagePart();

            if (part != null)
            {
                part.Clear();
            }
        }
Ejemplo n.º 2
0
        /**
         * Commit Changes to the underlying OPC namespace
         */

        public virtual void Commit()
        {
            if (extPart == null && !NEW_EXT_INSTANCE.ToString().Equals(ext.props.ToString()))
            {
                try
                {
                    PackagePartName prtname = PackagingUriHelper.CreatePartName("/docProps/app.xml");
                    pkg.AddRelationship(prtname, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
                    extPart = pkg.CreatePart(prtname, "application/vnd.openxmlformats-officedocument.extended-properties+xml");
                }
                catch (InvalidFormatException e)
                {
                    throw new POIXMLException(e);
                }
            }
            if (custPart == null && !NEW_CUST_INSTANCE.ToString().Equals(cust.props.ToString()))
            {
                try
                {
                    PackagePartName prtname = PackagingUriHelper.CreatePartName("/docProps/custom.xml");
                    pkg.AddRelationship(prtname, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties");
                    custPart = pkg.CreatePart(prtname, "application/vnd.openxmlformats-officedocument.custom-properties+xml");
                }
                catch (InvalidFormatException e)
                {
                    throw new POIXMLException(e);
                }
            }
            if (extPart != null)
            {
                Stream out1 = extPart.GetOutputStream();

                if (extPart.Size > 0)
                {
                    extPart.Clear();
                }
                ext.props.Save(out1);
                out1.Dispose();
            }
            if (custPart != null)
            {
                Stream out1 = custPart.GetOutputStream();
                cust.props.Save(out1);
                out1.Dispose();
            }
        }