NanoXLSX.Reader 3.0.0-rc.2
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 © 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
8using System;
9using System.IO;
10using System.Xml;
11using NanoXLSX.Interfaces.Plugin;
13using NanoXLSX.Registry;
14using NanoXLSX.Registry.Attributes;
15
17{
21 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.MetadataAppReader)]
22 public class MetadataAppReader : IPlugInReader
23 {
24 private MemoryStream stream;
25
26 #region properties
30 public Workbook Workbook { get; set; }
31 #endregion
32
33 #region constructors
37 internal MetadataAppReader()
38 {
39 }
40
41 #endregion
42
43 #region methods
50 public void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions)
51 {
52 this.stream = stream;
53 this.Workbook = workbook;
54 }
55
60 public void Execute()
61 {
62 try
63 {
64 using (stream) // Close after processing
65 {
66 Metadata metadata = Workbook.WorkbookMetadata;
67
68 XmlDocument xr = new XmlDocument
69 {
70 XmlResolver = null
71 };
72 using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings() { XmlResolver = null }))
73 {
74 xr.Load(reader);
75 foreach (XmlNode node in xr.DocumentElement.ChildNodes)
76 {
77 if (node.LocalName.Equals("Application", StringComparison.OrdinalIgnoreCase))
78 {
79 metadata.Application = node.InnerText;
80 }
81 else if (node.LocalName.Equals("AppVersion", StringComparison.OrdinalIgnoreCase))
82 {
83 metadata.ApplicationVersion = node.InnerText;
84 }
85 else if (node.LocalName.Equals("Company", StringComparison.OrdinalIgnoreCase))
86 {
87 metadata.Company = node.InnerText;
88 }
89 else if (node.LocalName.Equals("Manager", StringComparison.OrdinalIgnoreCase))
90 {
91 metadata.Manager = node.InnerText;
92 }
93 else if (node.LocalName.Equals("HyperlinkBase", StringComparison.OrdinalIgnoreCase))
94 {
95 metadata.HyperlinkBase = node.InnerText;
96 }
97 }
98 RederPlugInHandler.HandleInlineQueuePlugins(ref stream, Workbook, PlugInUUID.MetadataAppInlineReader);
99 }
100 }
101 }
102 catch (Exception ex)
103 {
104 throw new NanoXLSX.Exceptions.IOException("The XML entry could not be read from the input stream. Please see the inner exception:", ex);
105 }
106 }
107 #endregion
108 }
109}
Class representing a reader for the App metadata file (docProps) embedded in XLSX files.
void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions)
Initialization method (interface implementation).
void Execute()
Method to execute the main logic of the plug-in (interface implementation).
Workbook Workbook
Workbook reference where read data is stored (should not be null).