NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
Column.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
10using NanoXLSX.Utils;
11
12namespace NanoXLSX
13{
17 public class Column
18 {
19 private int number;
20 private string columnAddress;
21 private float width;
22 private Style defaultColumnStyle;
23
27 public string ColumnAddress
28 {
29 get { return columnAddress; }
30 set
31 {
32 if (string.IsNullOrEmpty(value))
33 {
34 throw new RangeException("The passed address was null or empty");
35 }
36 number = Cell.ResolveColumn(value);
37 columnAddress = ParserUtils.ToUpper(value);
38 }
39 }
40
44 public bool HasAutoFilter { get; set; }
48 public bool IsHidden { get; set; }
49
53 public int Number
54 {
55 get { return number; }
56 set
57 {
58 columnAddress = Cell.ResolveColumnAddress(value);
59 number = value;
60 }
61 }
62
66 public float Width
67 {
68 get { return width; }
69 set
70 {
71 if (value < Worksheet.MinColumnWidth || value > Worksheet.MaxColumnWidth)
72 {
73 throw new RangeException("The passed column width is out of range (" + Worksheet.MinColumnWidth + " to " + Worksheet.MaxColumnWidth + ")");
74 }
75 width = value;
76 }
77 }
78
83 {
84 get { return this.defaultColumnStyle; }
85 }
86
93 public Style SetDefaultColumnStyle(Style defaultColumnStyle, bool unmanaged = false)
94 {
95 if (defaultColumnStyle == null)
96 {
97 this.defaultColumnStyle = null;
98 return null;
99 }
100 if (unmanaged)
101 {
102 this.defaultColumnStyle = defaultColumnStyle;
103 }
104 else
105 {
106 this.defaultColumnStyle = StyleRepository.Instance.AddStyle(defaultColumnStyle);
107 }
108 return this.defaultColumnStyle;
109 }
110
114 private Column()
115 {
117 defaultColumnStyle = null;
118 }
119
124 public Column(int columnCoordinate) : this()
125 {
126 Number = columnCoordinate;
127 }
128
133 public Column(string columnAddress) : this()
134 {
135 ColumnAddress = columnAddress;
136 }
137
142 internal Column Copy()
143 {
144 Column copy = new Column
145 {
146 IsHidden = this.IsHidden,
147 Width = this.width,
148 HasAutoFilter = this.HasAutoFilter,
149 columnAddress = this.columnAddress,
150 number = this.number,
151 defaultColumnStyle = this.defaultColumnStyle
152 };
153 return copy;
154 }
155
156 }
157}
Class representing a cell of a worksheet.
Definition Cell.cs:24
static int ResolveColumn(string columnAddress)
Gets the column number from the column address (A - XFD).
Definition Cell.cs:840
static string ResolveColumnAddress(int columnNumber)
Gets the column address (A - XFD).
Definition Cell.cs:867
Class representing a column of a worksheet.
Definition Column.cs:18
float Width
Width of the column.
Definition Column.cs:67
string ColumnAddress
Column address (A to XFD).
Definition Column.cs:28
int Number
Column number (0 to 16383).
Definition Column.cs:54
Style SetDefaultColumnStyle(Style defaultColumnStyle, bool unmanaged=false)
Sets the default style of the column.
Definition Column.cs:93
bool HasAutoFilter
If true, the column has auto filter applied, otherwise not.
Definition Column.cs:44
Style DefaultColumnStyle
Gets the default style of the column.
Definition Column.cs:83
Column(int columnCoordinate)
Constructor with column number.
Definition Column.cs:124
Column(string columnAddress)
Constructor with column address.
Definition Column.cs:133
bool IsHidden
If true, the column is hidden, otherwise visible.
Definition Column.cs:48
Class for exceptions regarding range incidents (e.g. out-of-range).
Class to manage all styles at runtime, before writing XLSX files. The main purpose is deduplication a...
static StyleRepository Instance
Gets the singleton instance of the repository.
Style AddStyle(Style style)
Adds a style to the repository and returns the actual reference.
Class representing a Style with sub classes within a style sheet. An instance of this class is only a...
Definition Style.cs:18
Class providing static methods to parse string values to specific types or to print object as languag...
static string ToUpper(string input)
Transforms a string to upper case with null check and invariant culture.
Class representing a worksheet of a workbook.
Definition Worksheet.cs:26
static readonly float DefaultWorksheetColumnWidth
Default column width as constant.
Definition Worksheet.cs:40
static readonly float MinColumnWidth
Minimum column width as constant.
Definition Worksheet.cs:59
static readonly float MaxColumnWidth
Maximum column width as constant.
Definition Worksheet.cs:70