Save() 개인적인 메소드

Saves the document properties back to the package.
private Save ( ) : void
리턴 void
예제 #1
0
        /// <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();

            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();
        }
예제 #2
0
        /// <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 (_vba == null && !_package.Package.PartExists(new Uri(ExcelVbaProject.PartUri, UriKind.Relative)))
            {
                if (Part.ContentType != ExcelPackage.contentTypeWorkbookDefault)
                {
                    Part.ContentType = ExcelPackage.contentTypeWorkbookDefault;
                }
            }
            else
            {
                if (Part.ContentType != ExcelPackage.contentTypeWorkbookMacroEnabled)
                {
                    Part.ContentType = 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();
                worksheet.Part.SaveHandler = worksheet.SaveHandler;
            }

            // Issue 15252: save SharedStrings only once
            Packaging.ZipPackagePart part;
            if (_package.Package.PartExists(SharedStringsUri))
            {
                part = _package.Package.GetPart(SharedStringsUri);
            }
            else
            {
                part = _package.Package.CreatePart(SharedStringsUri, @"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml", _package.Compression);
                Part.CreateRelationship(UriHelper.GetRelativeUri(WorkbookUri, SharedStringsUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/sharedStrings");
            }

            part.SaveHandler = SaveSharedStringHandler;
            //UpdateSharedStringsXml();

            // Data validation
            ValidateDataValidations();

            //VBA
            if (_vba != null)
            {
                VbaProject.Save();
            }
        }
예제 #3
0
        /// <summary>
        /// Saves the workbook and all its components to the package.
        /// For internal use only!
        /// </summary>
        protected internal void Save()          // Workbook Save
        {
            // ensure we have at least one worksheet
            if (Worksheets.Count == 0)
            {
                throw new Exception("Workbook Save Error: the workbook must contain at least one worksheet!");
            }

            #region Delete calcChain component
            // if the calcChain component exists, we should delete it to force Excel to recreate it
            // when the spreadsheet is next opened
            if (_xlPackage.Package.PartExists(_uriCalcChain))
            {
                //  there will be a relationship with the workbook, so first delete the relationship
                Uri calcChain = new Uri("calcChain.xml", UriKind.Relative);
                foreach (PackageRelationship relationship in _xlPackage.Workbook.Part.GetRelationships())
                {
                    if (relationship.TargetUri == calcChain)
                    {
                        _xlPackage.Workbook.Part.DeleteRelationship(relationship.Id);
                        break;
                    }
                }
                // delete the calcChain component
                _xlPackage.Package.DeletePart(_uriCalcChain);
            }
            #endregion

            // save the workbook
            if (_xmlWorkbook != null)
            {
                _xlPackage.SavePart(WorkbookUri, _xmlWorkbook);
                _xlPackage.WriteDebugFile(_xmlWorkbook, "xl", "workbook.xml");
            }

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

            // save the style sheet
            if (_xmlStyles != null)
            {
                _xlPackage.SavePart(StylesUri, _xmlStyles);
                _xlPackage.WriteDebugFile(_xmlStyles, "xl", "styles.xml");
            }

            // save the shared strings
            if (_xmlSharedStrings != null)
            {
                _xlPackage.SavePart(SharedStringsUri, _xmlSharedStrings);
                _xlPackage.WriteDebugFile(_xmlSharedStrings, "xl", "sharedstrings.xml");
            }

            // save all the open worksheets
            foreach (ExcelWorksheet worksheet in Worksheets)
            {
                worksheet.Save();
            }
        }
예제 #4
0
        /// <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 (_vba == null && !_package.Package.PartExists(new Uri(ExcelVbaProject.PartUri, UriKind.Relative)))
            {
                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 (_vba != null) //VBA does not exist or is untouched, so ignore
            {
                VbaProject.Save();
            }
        }
예제 #5
0
        /// <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)
                {
                    Part.ContentType = ExcelPackage.contentTypeWorkbookDefault;
                }
            }
            else
            {
                if (Part.ContentType != ExcelPackage.contentTypeWorkbookMacroEnabled)
                {
                    Part.ContentType = 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();
                worksheet.Part.SaveHandler = worksheet.SaveHandler;
            }

            var part = _package.Package.CreatePart(SharedStringsUri, ExcelPackage.contentTypeSharedString, _package.Compression);

            part.SaveHandler = SaveSharedStringHandler;
            Part.CreateRelationship(UriHelper.GetRelativeUri(WorkbookUri, SharedStringsUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/sharedStrings");
            //UpdateSharedStringsXml();

            // Data validation
            ValidateDataValidations();

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