NanoXLSX.Compatibility 3.2.0
Loading...
Searching...
No Matches
ExternalCellValue.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;
9
10namespace NanoXLSX
11{
15 public class ExternalCellValue
16 {
20 public enum DataType
21 {
31#pragma warning disable CA1720
33#pragma warning restore CA1720
36 }
37
41 public string Value { get; private set; }
46
47 public DataType Type { get; private set; }
48
52 internal int? CellMetadata { get; set; }
53
63 public ExternalCellValue(string value, DataType type)
64 {
65 if (value == null || type == DataType.Empty)
66 {
67 Value = "";
68 Type = DataType.Empty;
69 return;
70 }
71
72 Value = NormalizeValue(value, type);
73 Type = type;
74 }
75
81 public ExternalCellValue(string value) : this(value, DataType.String) { }
82
90 private static string NormalizeValue(string value, DataType type)
91 {
92 switch (type)
93 {
94 case DataType.Boolean:
95 if (value == "1" || value.Equals("true", StringComparison.OrdinalIgnoreCase))
96 {
97 return "1";
98 }
99 if (value == "0" || value.Equals("false", StringComparison.OrdinalIgnoreCase))
100 {
101 return "0";
102 }
103 throw new ArgumentException("An invalid boolean value was provided (0 or 1 are expected): " + value);
104 default:
105 return value;
106 }
107 }
108 }
109}
ExternalCellValue(string value)
Constructor with value. The type DataType.String will be used as default type.
DataType Type
Type of the external, cached cell value.
DataType
Enum for the data type of the external cell.
@ String
External cell value is a string reference.
@ Boolean
External cell value is boolean.
@ Date
External cell value is date or date and time (ISO 8601).
@ Error
External cell value is an error and not actually a value.
@ Number
External cell value is a number. This is the implicit default, if not specified.
@ Empty
Not a real type for external cells, but used to mark a non-cached cell value. "0" will be shown as ca...
ExternalCellValue(string value, DataType type)
Constructor with value and type.
string Value
Value of the external, cached cell as string representation.