NanoXLSX.Reader 3.2.1
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 : IDocumentReader
24 {
25 private Stream stream;
26
27 #region properties
31 public virtual string DocumentType { get { return @"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"; } }
32
36 public Workbook Workbook { get; set; }
40 public IOptions Options { get; set; }
44 public Action<Stream, Workbook, string, IOptions, int?> InlinePluginHandler { get; set; }
45 #endregion
46
47 #region constructors
51 internal MetadataAppReader()
52 {
53 }
54
55 #endregion
56
57 #region methods
65 public void Init(Stream stream, Workbook workbook, IOptions readerOptions, Action<Stream, Workbook, string, IOptions, int?> inlinePluginHandler)
66 {
67 this.stream = stream;
68 this.Workbook = workbook;
69 this.Options = readerOptions;
70 this.InlinePluginHandler = inlinePluginHandler;
71 }
72
77 public void Execute()
78 {
79 try
80 {
81 using (stream) // Close after processing
82 {
83 Metadata metadata = Workbook.WorkbookMetadata;
84 using (XmlReader reader = XmlReader.Create(stream, XmlStreamUtils.CreateSettings()))
85 {
86 while (reader.Read())
87 {
88 if (reader.NodeType != XmlNodeType.Element)
89 {
90 continue;
91 }
92 if (XmlStreamUtils.IsElement(reader, "Application"))
93 {
94 metadata.Application = XmlStreamUtils.ReadElementText(reader);
95 }
96 else if (XmlStreamUtils.IsElement(reader, "AppVersion"))
97 {
98 metadata.ApplicationVersion = XmlStreamUtils.ReadElementText(reader);
99 }
100 else if (XmlStreamUtils.IsElement(reader, "Company"))
101 {
102 metadata.Company = XmlStreamUtils.ReadElementText(reader);
103 }
104 else if (XmlStreamUtils.IsElement(reader, "Manager"))
105 {
106 metadata.Manager = XmlStreamUtils.ReadElementText(reader);
107 }
108 else if (XmlStreamUtils.IsElement(reader, "HyperlinkBase"))
109 {
110 metadata.HyperlinkBase = XmlStreamUtils.ReadElementText(reader);
111 }
112 }
113 InlinePluginHandler?.Invoke(stream, Workbook, PlugInUUID.MetadataAppInlineReader, Options, null);
114 }
115 }
116 }
117 catch (Exception ex)
118 {
119 throw new NanoXLSX.Exceptions.IOException("The XML entry could not be read from the input stream. Please see the inner exception:", ex);
120 }
121 }
122 #endregion
123 }
124}
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).
virtual string DocumentType
Gets the relationship type URI of the app metadata document.
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).