Пример #1
0
 /// <summary>
 /// Saves the XmlDocument into the package at the specified Uri.
 /// </summary>
 /// <param name="uri">The Uri of the component</param>
 /// <param name="xmlDoc">The XmlDocument to save</param>
 internal void SaveWorkbook(Uri uri, XmlDocument xmlDoc)
 {
     Packaging.ZipPackagePart part = _package.GetPart(uri);
     if (Workbook.VbaProject == null)
     {
         if (part.ContentType != contentTypeWorkbookDefault)
         {
             part = _package.CreatePart(uri, contentTypeWorkbookDefault, Compression);
         }
     }
     else
     {
         if (part.ContentType != contentTypeWorkbookMacroEnabled)
         {
             var rels = part.GetRelationships();
             _package.DeletePart(uri);
             part = Package.CreatePart(uri, contentTypeWorkbookMacroEnabled);
             foreach (var rel in rels)
             {
                 Package.DeleteRelationship(rel.Id);
                 part.CreateRelationship(rel.TargetUri, rel.TargetMode, rel.RelationshipType);
             }
         }
     }
     xmlDoc.Save(part.GetStream(FileMode.Create, FileAccess.Write));
 }
Пример #2
0
        /// <summary>
        /// Saves the XmlDocument into the package at the specified Uri.
        /// </summary>
        /// <param name="uri">The Uri of the component</param>
        /// <param name="xmlDoc">The XmlDocument to save</param>
        internal void SaveWorkbook(Uri uri, XmlDocument xmlDoc)
        {
            Packaging.ZipPackagePart part = _package.GetPart(uri);
            if (Workbook.VbaProject == null)
            {
                if (part.ContentType != contentTypeWorkbookDefault)
                {
                    part = _package.CreatePart(uri, contentTypeWorkbookDefault, Compression);
                }
            }
            else
            {
                if (part.ContentType != contentTypeWorkbookMacroEnabled)
                {
                    var rels = part.GetRelationships();
                    _package.DeletePart(uri);
                    part = Package.CreatePart(uri, contentTypeWorkbookMacroEnabled);
                    foreach (ZipPackageRelationship rel in rels)
                    {
                        Package.DeleteRelationship(rel.Id);
                        part.CreateRelationship(rel.TargetUri, rel.TargetMode, rel.RelationshipType);
                    }
                }
            }
            var stream = part.GetStream(FileMode.Create, FileAccess.Write);
            var xr     = new XmlTextWriter(stream, Encoding.UTF8);

            xr.Formatting = Formatting.None;

            xmlDoc.Save(xr);
        }