Provides access to the properties bag of any office document (i.e. Word, Excel etc.)
示例#1
0
 public void Dispose()
 {
     if (this.SharedStrings != null)
     {
         this.SharedStrings.Clear();
         this.SharedStrings = null;
     }
     if (this.SharedStringsList != null)
     {
         this.SharedStringsList.Clear();
         this.SharedStringsList = null;
     }
     this._vba = null;
     if (this._worksheets != null)
     {
         this._worksheets.Dispose();
         this._worksheets = null;
     }
     this.Package     = null;
     this._properties = null;
     if (this._formulaParser != null)
     {
         this._formulaParser.Dispose();
         this._formulaParser = null;
     }
 }
示例#2
0
 public void Dispose()
 {
     if (_sharedStrings != null)
     {
         _sharedStrings.Clear();
         _sharedStrings = null;
     }
     if (_sharedStringsList != null)
     {
         _sharedStringsList.Clear();
         _sharedStringsList = null;
     }
     _vba = null;
     if (_worksheets != null)
     {
         _worksheets.Dispose();
         _worksheets = null;
     }
     _package    = null;
     _properties = null;
     if (_formulaParser != null)
     {
         _formulaParser.Dispose();
         _formulaParser = null;
     }
 }
        public static Dictionary <string, object> ToDictionary(this OfficeProperties props)
        {
            var dic = new Dictionary <string, object>();

            dic[nameof(props.Application)]       = props.Application;
            dic[nameof(props.AppVersion)]        = props.AppVersion;
            dic[nameof(props.Author)]            = props.Author;
            dic[nameof(props.Category)]          = props.Category;
            dic[nameof(props.Comments)]          = props.Comments;
            dic[nameof(props.Company)]           = props.Company;
            dic[nameof(props.Created)]           = props.Created;
            dic[nameof(props.HyperlinkBase)]     = props.HyperlinkBase;
            dic[nameof(props.HyperlinksChanged)] = props.HyperlinksChanged;
            dic[nameof(props.Keywords)]          = props.Keywords;
            dic[nameof(props.LastModifiedBy)]    = props.LastModifiedBy;
            dic[nameof(props.LastPrinted)]       = props.LastPrinted;
            dic[nameof(props.LinksUpToDate)]     = props.LinksUpToDate;
            dic[nameof(props.Manager)]           = props.Manager;
            dic[nameof(props.Modified)]          = props.Modified;
            dic[nameof(props.ScaleCrop)]         = props.ScaleCrop;
            dic[nameof(props.SharedDoc)]         = props.SharedDoc;
            dic[nameof(props.Status)]            = props.Status;
            dic[nameof(props.Subject)]           = props.Subject;
            dic[nameof(props.Title)]             = props.Title;
            return(dic);
        }
        /// <summary>
        /// Sets the document metadata from model.
        /// </summary>
        /// <param name="properties">The document properties.</param>
        /// <param name="metadata">Model metadata information.</param>
        /// <returns>
        /// An <see cref="T:OfficeOpenXml.OfficeProperties"/> reference which contains the document metadata.
        /// </returns>
        public static OfficeProperties SetDocumentMetadataFromModel(this OfficeProperties properties, DocumentMetadataModel metadata)
        {
            SentinelHelper.ArgumentNull(properties);
            SentinelHelper.ArgumentNull(metadata);

            if (!string.IsNullOrEmpty(metadata.Title))
            {
                properties.Title = metadata.Title;
            }

            if (!string.IsNullOrEmpty(metadata.Subject))
            {
                properties.Subject = metadata.Subject;
            }

            if (!string.IsNullOrEmpty(metadata.Author))
            {
                properties.Author = metadata.Author;
            }

            if (!string.IsNullOrEmpty(metadata.Manager))
            {
                properties.Manager = metadata.Manager;
            }

            if (!string.IsNullOrEmpty(metadata.Company))
            {
                properties.Company = metadata.Company;
            }

            if (!string.IsNullOrEmpty(metadata.Category))
            {
                properties.Category = metadata.Category;
            }

            if (!string.IsNullOrEmpty(metadata.Keywords))
            {
                properties.Keywords = metadata.Keywords;
            }

            if (!string.IsNullOrEmpty(metadata.Comments))
            {
                properties.Comments = metadata.Comments;
            }

            if (!string.IsNullOrEmpty(metadata.Url))
            {
                properties.HyperlinkBase = new Uri(metadata.Url);
            }

            return(properties);
        }
示例#5
0
        public void Dispose()
        {
            _sharedStrings.Clear();
            _sharedStringsList.Clear();

            _sharedStrings     = null;
            _sharedStringsList = null;
            _vba = null;
            _worksheets.Dispose();
            _package       = null;
            _worksheets    = null;
            _properties    = null;
            _formulaParser = null;
        }
 public static void Clone(this OfficeProperties props, OfficeProperties values)
 {
     props.Application       = values.Application;
     props.AppVersion        = values.AppVersion;
     props.Author            = values.Author;
     props.Category          = values.Category;
     props.Comments          = values.Comments;
     props.Company           = values.Company;
     props.Created           = values.Created;
     props.HyperlinkBase     = values.HyperlinkBase;
     props.HyperlinksChanged = values.HyperlinksChanged;
     props.Keywords          = values.Keywords;
     props.LastModifiedBy    = values.LastModifiedBy;
     props.LastPrinted       = values.LastPrinted;
     props.LinksUpToDate     = values.LinksUpToDate;
     props.Manager           = values.Manager;
     props.Modified          = values.Modified;
     props.ScaleCrop         = values.ScaleCrop;
     props.SharedDoc         = values.SharedDoc;
     props.Status            = values.Status;
     props.Subject           = values.Subject;
     props.Title             = values.Title;
 }
示例#7
0
 public void Dispose()
 {
     _sharedStrings.Clear();
     _sharedStringsList.Clear();
     
     _sharedStrings = null;
     _sharedStringsList = null;
     _vba = null;
     if (_worksheets != null)
     {
         _worksheets.Dispose();
         _worksheets = null;
     }
     _package = null;
     _properties = null;
     if (_formulaParser != null)
     {
         _formulaParser.Dispose();
         _formulaParser = null;
     }   
 }
        /// <summary>
        /// Sets the document metadata from model.
        /// </summary>
        /// <param name="properties">The document properties.</param>
        /// <param name="metadata">Model metadata information.</param>
        /// <returns>
        /// An <see cref="OfficeProperties"/> reference which contains the document metadata.
        /// </returns>
        public static OfficeProperties SetDocumentMetadata(this OfficeProperties properties, XlsxDocumentMetadataSettings metadata)
        {
            SentinelHelper.ArgumentNull(properties, nameof(properties));
            SentinelHelper.ArgumentNull(metadata, nameof(metadata));

            // Core properties
            properties.Created  = DateTime.Now;
            properties.Modified = DateTime.Now;

            if (!string.IsNullOrEmpty(metadata.Title))
            {
                properties.Title = metadata.Title;
            }

            if (!string.IsNullOrEmpty(metadata.Subject))
            {
                properties.Subject = metadata.Subject;
            }

            if (!string.IsNullOrEmpty(metadata.Author))
            {
                properties.Author = metadata.Author;
            }

            if (!string.IsNullOrEmpty(metadata.Manager))
            {
                properties.Manager = metadata.Manager;
            }

            if (!string.IsNullOrEmpty(metadata.Company))
            {
                properties.Company = metadata.Company;
            }

            if (!string.IsNullOrEmpty(metadata.Category))
            {
                properties.Category = metadata.Category;
            }

            if (!string.IsNullOrEmpty(metadata.Keywords))
            {
                properties.Keywords = metadata.Keywords;
            }

            if (!string.IsNullOrEmpty(metadata.Comments))
            {
                properties.Comments = metadata.Comments;
            }

            if (!string.IsNullOrEmpty(metadata.Url))
            {
                var isValid = Uri.IsWellFormedUriString(metadata.Url, UriKind.RelativeOrAbsolute);
                if (isValid)
                {
                    try
                    {
                        properties.HyperlinkBase = new Uri(metadata.Url, UriKind.RelativeOrAbsolute);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            return(properties);
        }
 public static void SetProperties(this ExcelWorkbook wb, OfficeProperties props) => wb.Properties.Clone(props);
示例#10
0
        public static void WorksheetSaveCopyAs(this ExcelWorksheet wks, string fileName, OfficeProperties props)
        {
            var fi = new FileInfo(fileName);

            using (var xl = new ExcelPackage(fi)) {
                var ws = xl.Workbook.Worksheets.Add(wks.Name, wks);
                xl.Workbook.Properties.Clone(props);
                xl.SaveAs(fi);
            }
        }