Пример #1
0
        /// <summary>
        /// Saves the worksheet to the package.  For internal use only.
        /// </summary>
        protected internal void Save()          // Worksheet Save
        {
            #region Delete the printer settings component (if it exists)
            // we also need to delete the relationship from the pageSetup tag
            var pageSetup = WorksheetXml.XPathSelectElement("//d:pageSetup", NameSpaceManager);
            if (pageSetup != null)
            {
                XAttribute attr = pageSetup.Attribute(ExcelPackage.schemaRelationships + "id");
                if (attr != null)
                {
                    string relID = attr.Value;
                    // first delete the attribute from the XML
                    attr.Remove();

                    // get the URI
                    PackageRelationship relPrinterSettings = Part.GetRelationship(relID);
                    Uri printerSettingsUri = new Uri("/xl" + relPrinterSettings.TargetUri.ToString().Replace("..", ""), UriKind.Relative);

                    // now delete the relationship
                    Part.DeleteRelationship(relPrinterSettings.Id);

                    // now delete the part from the package
                    xlPackage.Package.DeletePart(printerSettingsUri);
                }
            }
            #endregion

            if (_worksheetXml != null)
            {
                // save the header & footer (if defined)
                if (_headerFooter != null)
                {
                    HeaderFooter.Save();
                }
                // replace the numeric Cell IDs we inserted with AddNumericCellIDs()
                ReplaceNumericCellIDs();

                // save worksheet to package
                PackagePart partPack = xlPackage.Package.GetPart(WorksheetUri);
                WorksheetXml.Save(partPack.GetStream(FileMode.Create, FileAccess.Write));
                xlPackage.WriteDebugFile(WorksheetXml, @"xl\worksheets", "sheet" + SheetID + ".xml");
            }
        }