NanoXLSX.Reader 3.0.0-rc.2
Loading...
Searching...
No Matches
ReaderOptions.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.Collections.Generic;
9using System.Globalization;
10using NanoXLSX.Exceptions;
11using NanoXLSX.Interfaces.Plugin;
12
13namespace NanoXLSX
14{
18 public class ReaderOptions : IOptions
19 {
20
24 public const string DefaultDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
25
29 public const string DefaultTimeSpanFormat = "hh\\:mm\\:ss";
30
34 public static readonly CultureInfo DefaultCultureInfo = CultureInfo.InvariantCulture;
35
62
66 public enum ColumnType
67 {
68#pragma warning disable CA1720 // Identifier contains type name
72 Numeric,
97#pragma warning restore CA1720 // Identifier contains type name
98 }
99
104 public bool EnforceDateTimesAsNumbers { get; set; }
105
110 public bool EnforcePhoneticCharacterImport { get; set; }
111
115 public bool EnforceEmptyValuesAsString { get; set; }
116
120 public bool EnforceStrictValidation { get; set; }
121
125 public GlobalType GlobalEnforcingType { get; set; } = GlobalType.Default;
126
127
131 public Dictionary<int, ColumnType> EnforcedColumnTypes { get; private set; } = new Dictionary<int, ColumnType>();
132
136 public int EnforcingStartRowNumber { get; set; }
137
142 public string DateTimeFormat { get; set; } = DefaultDateTimeFormat;
143
148 public string TimeSpanFormat { get; set; } = DefaultTimeSpanFormat;
149
154 public CultureInfo TemporalCultureInfo { get; set; } = DefaultCultureInfo;
155
160 public bool IgnoreNotSupportedPasswordAlgorithms { get; set; }
161
167 public void AddEnforcedColumn(string columnAddress, ColumnType type)
168 {
169 this.EnforcedColumnTypes.Add(Cell.ResolveColumn(columnAddress), type);
170 }
171
177 public void AddEnforcedColumn(int columnNumber, ColumnType type)
178 {
179 this.EnforcedColumnTypes.Add(columnNumber, type);
180 }
181 }
182}
The reader options define global rules, applied when loading a worksheet. The options are mainly to o...
ColumnType
Column types to enforce during the read process. The types are tried to be applied on all cells of a ...
@ String
Cells are all imported as strings, using the ToString() method.
@ Date
Cells are tried to be imported as dates (DateTime). See also DateTimeFormat, TimeSpanFormat and Tempo...
@ Decimal
Cells are tried to be imported as numbers (enforcing decimal).
@ Time
Cells are tried to be imported as times (TimeSpan).
@ Bool
Cells are tried to be imported as bools.
@ Double
Cells are tried to be imported as numbers (enforcing double).
int EnforcingStartRowNumber
The row number (zero-based) where enforcing rules are started to be applied. This is,...
string DateTimeFormat
Format if DateTime values are cast to strings or DateTime objects are parsed from strings....
void AddEnforcedColumn(string columnAddress, ColumnType type)
Adds a type enforcing rule to the passed column address.
Dictionary< int, ColumnType > EnforcedColumnTypes
Type enforcing rules during the read process for particular columns.
void AddEnforcedColumn(int columnNumber, ColumnType type)
Adds a type enforcing rule to the passed column number (zero-based).
bool IgnoreNotSupportedPasswordAlgorithms
If set to true, worksheet or workbook protection passwords with unknown / not supported algorithms wi...
bool EnforceDateTimesAsNumbers
If true, date or time values (default format number 14 or 21) will be interpreted as numeric values g...
static readonly CultureInfo DefaultCultureInfo
Default culture info instance (invariant culture) used for date and time parsing, if no custom cultur...
string TimeSpanFormat
Format if TimeSpan values are cast to strings.
bool EnforcePhoneticCharacterImport
If true, phonetic characters (like ruby characters / Furigana / Zhuyin fuhao) in strings are added in...
GlobalType
Global conversion types to enforce during the load process. All types other than GlobalType....
@ AllNumbersToDouble
All numbers are cast to doubles.
@ AllNumbersToDecimal
All numbers are cast to decimal.
@ Default
No global strategy. All numbers are tried to be cast to the most suitable types.
@ EverythingToString
Every cell is cast to a string.
@ AllNumbersToInt
All numbers are cast to integers. Floating point numbers will be rounded (commercial rounding) to the...
CultureInfo TemporalCultureInfo
Culture info instance, used to parse DateTime or TimeSpan objects from strings. If null,...
GlobalType GlobalEnforcingType
Global strategy to handle cell values. The default will not enforce any general casting,...
bool EnforceStrictValidation
If true, invalid data, like column widths or row height that are out of range, will cause an exceptio...
const string DefaultDateTimeFormat
Default format if DateTime values are cast to strings.
bool EnforceEmptyValuesAsString
If true, empty cells will be interpreted as type of string with an empty value. If false,...
const string DefaultTimeSpanFormat
Default format if TimeSpan values are cast to strings.