NanoXLSX.Reader 3.1.0
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;
15using NanoXLSX.Utils.Xml;
16
18{
22 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.MetadataAppReader)]
23 public class MetadataAppReader : IPluginBaseReader
24 {
25 private Stream stream;
26
27 #region properties
31 public Workbook Workbook { get; set; }
35 public IOptions Options { get; set; }
39 public Action<Stream, Workbook, string, IOptions, int?> InlinePluginHandler { get; set; }
40 #endregion
41
42 #region constructors
46 internal MetadataAppReader()
47 {
48 }
49
50 #endregion
51
52 #region methods
60 public void Init(Stream stream, Workbook workbook, IOptions readerOptions, Action<Stream, Workbook, string, IOptions, int?> inlinePluginHandler)
61 {
62 this.stream = stream;
63 this.Workbook = workbook;
64 this.Options = readerOptions;
65 this.InlinePluginHandler = inlinePluginHandler;
66 }
67
72 public void Execute()
73 {
74 try
75 {
76 using (stream) // Close after processing
77 {
78 Metadata metadata = Workbook.WorkbookMetadata;
79 using (XmlReader reader = XmlReader.Create(stream, XmlStreamUtils.CreateSettings()))
80 {
81 while (reader.Read())
82 {
83 if (reader.NodeType != XmlNodeType.Element)
84 {
85 continue;
86 }
87 if (XmlStreamUtils.IsElement(reader, "Application"))
88 {
89 metadata.Application = XmlStreamUtils.ReadElementText(reader);
90 }
91 else if (XmlStreamUtils.IsElement(reader, "AppVersion"))
92 {
93 metadata.ApplicationVersion = XmlStreamUtils.ReadElementText(reader);
94 }
95 else if (XmlStreamUtils.IsElement(reader, "Company"))
96 {
97 metadata.Company = XmlStreamUtils.ReadElementText(reader);
98 }
99 else if (XmlStreamUtils.IsElement(reader, "Manager"))
100 {
101 metadata.Manager = XmlStreamUtils.ReadElementText(reader);
102 }
103 else if (XmlStreamUtils.IsElement(reader, "HyperlinkBase"))
104 {
105 metadata.HyperlinkBase = XmlStreamUtils.ReadElementText(reader);
106 }
107 }
108 InlinePluginHandler?.Invoke(stream, Workbook, PlugInUUID.MetadataAppInlineReader, Options, null);
109 }
110 }
111 }
112 catch (Exception ex)
113 {
114 throw new NanoXLSX.Exceptions.IOException("The XML entry could not be read from the input stream. Please see the inner exception:", ex);
115 }
116 }
117 #endregion
118 }
119}
Class representing a reader for the App metadata file (docProps) embedded in XLSX files.
void Execute()
Method to execute the main logic of the plug-in (interface implementation).
Action< Stream, Workbook, string, IOptions, int?> InlinePluginHandler
Reference to the ReaderPlugInHandler, to be used for post operations in the Execute method.
void Init(Stream stream, Workbook workbook, IOptions readerOptions, Action< Stream, Workbook, string, IOptions, int?> inlinePluginHandler)
Initialization method (interface implementation).
Workbook Workbook
Workbook reference where read data is stored (should not be null).