Beispiel #1
0
 /// <summary>
 /// Saves the document properties back to the package.
 /// </summary>
 internal void Save()
 {
     if (_xmlPropertiesCore != null)
     {
         _package.SavePart(_uriPropertiesCore, _xmlPropertiesCore);
     }
     if (_xmlPropertiesExtended != null)
     {
         _package.SavePart(_uriPropertiesExtended, _xmlPropertiesExtended);
     }
     if (_xmlPropertiesCustom != null)
     {
         _package.SavePart(_uriPropertiesCustom, _xmlPropertiesCustom);
     }
 }
        /// <summary>
        /// Saves the workbook and all its components to the package.
        /// For internal use only!
        /// </summary>
        internal void Save()          // Workbook Save
        {
            if (Worksheets.Count == 0)
            {
                throw new InvalidOperationException("The workbook must contain at least one worksheet");
            }

            DeleteCalcChain();

            if (VbaProject == null)
            {
                if (Part.ContentType != ExcelPackage.contentTypeWorkbookDefault)
                {
                    ChangeContentTypeWorkbook(ExcelPackage.contentTypeWorkbookDefault);
                }
            }
            else
            {
                if (Part.ContentType != ExcelPackage.contentTypeWorkbookMacroEnabled)
                {
                    ChangeContentTypeWorkbook(ExcelPackage.contentTypeWorkbookMacroEnabled);
                }
            }

            UpdateDefinedNamesXml();

            // save the workbook
            if (_workbookXml != null)
            {
                _package.SavePart(WorkbookUri, _workbookXml);
            }

            // save the properties of the workbook
            if (_properties != null)
            {
                _properties.Save();
            }

            // save the style sheet
            Styles.UpdateXml();
            _package.SavePart(StylesUri, _stylesXml);

            // save all the open worksheets
            var isProtected = Protection.LockWindows || Protection.LockStructure;

            foreach (ExcelWorksheet worksheet in Worksheets)
            {
                if (isProtected && Protection.LockWindows)
                {
                    worksheet.View.WindowProtection = true;
                }
                worksheet.Save();
            }

            UpdateSharedStringsXml();

            // Data validation
            ValidateDataValidations();

            //VBA
            if (VbaProject != null)
            {
                VbaProject.Save();
            }
        }