NanoXLSX.Reader 3.0.0-rc.5
Loading...
Searching...
No Matches
MetadataAppReader.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 © 2026
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
8using System;
9using System.IO;
10using System.Xml;
11using NanoXLSX.Interfaces;
12using NanoXLSX.Interfaces.Reader;
13using NanoXLSX.Registry;
14using NanoXLSX.Registry.Attributes;
15
17{
21 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.MetadataAppReader)]
22 public class MetadataAppReader : IPluginBaseReader
23 {
24 private MemoryStream stream;
25
26 #region properties
30 public Workbook Workbook { get; set; }
34 public IOptions Options { get; set; }
38 public Action<MemoryStream, Workbook, string, IOptions, int?> InlinePluginHandler { get; set; }
39 #endregion
40
41 #region constructors
45 internal MetadataAppReader()
46 {
47 }
48
49 #endregion
50
51 #region methods
59 public void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions, Action<MemoryStream, Workbook, string, IOptions, int?> inlinePluginHandler)
60 {
61 this.stream = stream;
62 this.Workbook = workbook;
63 this.Options = readerOptions;
64 this.InlinePluginHandler = inlinePluginHandler;
65 }
66
71 public void Execute()
72 {
73 try
74 {
75 using (stream) // Close after processing
76 {
77 Metadata metadata = Workbook.WorkbookMetadata;
78
79 XmlDocument xr = new XmlDocument
80 {
81 XmlResolver = null
82 };
83 using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings() { XmlResolver = null }))
84 {
85 xr.Load(reader);
86 foreach (XmlNode node in xr.DocumentElement.ChildNodes)
87 {
88 if (node.LocalName.Equals("Application", StringComparison.OrdinalIgnoreCase))
89 {
90 metadata.Application = node.InnerText;
91 }
92 else if (node.LocalName.Equals("AppVersion", StringComparison.OrdinalIgnoreCase))
93 {
94 metadata.ApplicationVersion = node.InnerText;
95 }
96 else if (node.LocalName.Equals("Company", StringComparison.OrdinalIgnoreCase))
97 {
98 metadata.Company = node.InnerText;
99 }
100 else if (node.LocalName.Equals("Manager", StringComparison.OrdinalIgnoreCase))
101 {
102 metadata.Manager = node.InnerText;
103 }
104 else if (node.LocalName.Equals("HyperlinkBase", StringComparison.OrdinalIgnoreCase))
105 {
106 metadata.HyperlinkBase = node.InnerText;
107 }
108 }
109 InlinePluginHandler?.Invoke(stream, Workbook, PlugInUUID.MetadataAppInlineReader, Options, null);
110 }
111 }
112 }
113 catch (Exception ex)
114 {
115 throw new NanoXLSX.Exceptions.IOException("The XML entry could not be read from the input stream. Please see the inner exception:", ex);
116 }
117 }
118 #endregion
119 }
120}
Class representing a reader for the App metadata file (docProps) embedded in XLSX files.
Action< MemoryStream, Workbook, string, IOptions, int?> InlinePluginHandler
Reference to the ReaderPlugInHandler, to be used for post operations in the Execute method.
void Execute()
Method to execute the main logic of the plug-in (interface implementation).
void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions, Action< MemoryStream, Workbook, string, IOptions, int?> inlinePluginHandler)
Initialization method (interface implementation).
Workbook Workbook
Workbook reference where read data is stored (should not be null).