NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
Metadata.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.Reflection;
10using NanoXLSX.Utils;
11using FormatException = NanoXLSX.Exceptions.FormatException;
12
13namespace NanoXLSX
14{
18 public class Metadata
19 {
20
21 #region constants
25 public const string DefaultApplicationName = "NanoXLSX";
29 public static string DefaultApplicationVersion { get; private set; }
30 static Metadata()
31 {
32 Version vi = Assembly.GetExecutingAssembly().GetName().Version;
33 DefaultApplicationVersion = ParseVersion(vi.Major, vi.Minor, vi.Revision, vi.Build);
34 }
35 #endregion
36
37 #region privateFields
38 private string applicationVersion;
39 #endregion
40
41 #region properties
45 public string Application { get; set; }
50 public string ApplicationVersion
51 {
52 get { return applicationVersion; }
53 set
54 {
55 applicationVersion = value;
56 CheckVersion();
57 }
58 }
59
62 public string Category { get; set; }
66 public string Company { get; set; }
70 public string ContentStatus { get; set; }
74 public string Creator { get; set; }
78 public string Description { get; set; }
82 public string HyperlinkBase { get; set; }
86 public string Keywords { get; set; }
90 public string Manager { get; set; }
94 public string Subject { get; set; }
98 public string Title { get; set; }
99 #endregion
100
101 #region constructors
110 #endregion
111
112 #region methods
117 private void CheckVersion()
118 {
119 if (string.IsNullOrEmpty(applicationVersion))
120 { return; }
121 string[] split = applicationVersion.Split('.');
122 bool state = true;
123 if (split.Length != 2)
124 { state = false; }
125 else
126 {
127 if (split[1].Length < 1 || split[1].Length > 5)
128 { state = false; }
129 if (split[0].Length < 1 || split[0].Length > 5)
130 { state = false; }
131 }
132 if (!state)
133 {
134 throw new FormatException("The format of the version in the metadata is wrong (" + applicationVersion + "). Should be in the format and a range from '0.0' to '99999.99999'");
135 }
136 }
137 #endregion
138
139 #region staticMethods
151 public static string ParseVersion(int major, int minor, int build, int revision)
152 {
153 if (major < 0 || minor < 0 || build < 0 || revision < 0)
154 {
155 throw new FormatException("The format of the passed version is wrong. No negative number allowed.");
156 }
157 if (major > 99999)
158 {
159 throw new FormatException("The major number may not be bigger than 99999. The passed value is " + major);
160 }
161 string leftPart = ParserUtils.ToString(major);
162 string rightPart = ParserUtils.ToString(minor) + ParserUtils.ToString(build) + ParserUtils.ToString(revision);
163 rightPart = rightPart.TrimEnd('0');
164 if (rightPart == "")
165 { rightPart = "0"; }
166 else
167 {
168 if (rightPart.Length > 5)
169 {
170 rightPart = rightPart.Substring(0, 5);
171 }
172 }
173 return leftPart + "." + rightPart;
174 }
175 #endregion
176 }
177}
Class for exceptions regarding format error incidents.
string Title
Gets or sets the title of the workbook.
Definition Metadata.cs:98
static string DefaultApplicationVersion
Default application version, if not otherwise specified.
Definition Metadata.cs:29
string Creator
Gets or sets the creator of the workbook. Add more than one creator by using the semicolon (;) betwee...
Definition Metadata.cs:74
string ApplicationVersion
Gets or sets the version of the creation application. Default is the library version of NanoXLSX....
Definition Metadata.cs:51
string Company
Gets or sets the company owning the document. This value is for organizational purpose....
Definition Metadata.cs:66
string HyperlinkBase
Gets or sets the hyperlink base of the document.
Definition Metadata.cs:82
static string ParseVersion(int major, int minor, int build, int revision)
Method to parse a common version (major.minor.revision.build) into the compatible format (major....
Definition Metadata.cs:151
string Manager
Gets or sets the responsible manager of the document. This value is for organizational purpose.
Definition Metadata.cs:90
string Application
Gets or sets the application which created the workbook. Default is NanoXLSX.
Definition Metadata.cs:45
string Keywords
Gets or sets the keywords of the workbook. Separate particular keywords with semicolons (;).
Definition Metadata.cs:86
const string DefaultApplicationName
Default application name, if not otherwise specified.
Definition Metadata.cs:25
string Description
Gets or sets the description of the document or comment about it.
Definition Metadata.cs:78
string ContentStatus
Gets or sets the status of the document. There are no predefined values or restrictions about the con...
Definition Metadata.cs:70
string Subject
Gets or sets the subject of the workbook.
Definition Metadata.cs:94
Metadata()
Default constructor.
Definition Metadata.cs:105
string Category
Gets or sets the category of the document. There are no predefined values or restrictions about the c...
Definition Metadata.cs:62
Class providing static methods to parse string values to specific types or to print object as languag...
static string ToString(int input)
Transforms an integer to an invariant sting.