NanoXLSX.Writer 3.0.0-rc.3
Loading...
Searching...
No Matches
MetadataCoreWriter.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2025
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
9using NanoXLSX.Registry;
10using NanoXLSX.Registry.Attributes;
11using NanoXLSX.Utils;
12using NanoXLSX.Utils.Xml;
13using System;
14
16{
20 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.MetadataCoreWriter)]
21 internal class MetadataCoreWriter : IPlugInWriter
22 {
23 private XmlElement properties;
24
25 #region properties
29 public Workbook Workbook { get; set; }
30
34 public XmlElement XmlElement { get => properties; }
35
36 #endregion
37 #region constructors
41 internal MetadataCoreWriter()
42 {
43 }
44
45 #endregion
46 #region methods
51 public void Init(IBaseWriter baseWriter)
52 {
53 this.Workbook = baseWriter.Workbook;
54 }
55
59 public void Execute()
60 {
61 properties = XmlElement.CreateElement("coreProperties", "cp");
62 properties.AddNameSpaceAttribute("dc", "xmlns", "http://purl.org/dc/elements/1.1/");
63 properties.AddNameSpaceAttribute("cp", "xmlns", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
64 properties.AddNameSpaceAttribute("dcterms", "xmlns", "http://purl.org/dc/terms/");
65 properties.AddNameSpaceAttribute("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
66 Metadata md = Workbook.WorkbookMetadata;
67 properties.AddChildElementWithValue("title", md.Title, "dc");
68 properties.AddChildElementWithValue("subject", md.Subject, "dc");
69 properties.AddChildElementWithValue("creator", md.Creator, "dc");
70 properties.AddChildElementWithValue("lastModifiedBy", md.Creator, "cp");
71 properties.AddChildElementWithValue("keywords", md.Keywords, "cp");
72 properties.AddChildElementWithValue("description", md.Description, "dc");
73 string time = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ssZ", ParserUtils.InvariantCulture);
74 XmlElement child1 = properties.AddChildElementWithValue("created", time, "dcterms");
75 child1.AddAttribute("type", "dcterms:W3CDTF", "xsi");
76 XmlElement child2 = properties.AddChildElementWithValue("modified", time, "dcterms");
77 child2.AddAttribute("type", "dcterms:W3CDTF", "xsi");
78 properties.AddChildElementWithValue("category", md.Category, "cp");
79 properties.AddChildElementWithValue("contentStatus", md.ContentStatus, "cp");
80
81 WriterPlugInHandler.HandleInlineQueuePlugins(ref properties, Workbook, PlugInUUID.MetadataCoreInlineWriter);
82 }
83
84 #endregion
85 }
86}