NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
Address.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;
9
10namespace NanoXLSX
11{
15 public struct Address : IEquatable<Address>, IComparable<Address>
16 {
17 private readonly int column;
18 private readonly int row;
19 private readonly Cell.AddressType type;
20
24 public int Column { get => column; }
28 public int Row { get => row; }
29
33 public Cell.AddressType Type { get => type; }
34
40 public Address(int column, int row) : this(column, row, Cell.AddressType.Default)
41 {
42 // No actions
43 }
44
51 public Address(int column, int row, Cell.AddressType type)
52 {
55 this.column = column;
56 this.row = row;
57 this.type = type;
58 }
59
64 public Address(string address)
65 {
66 Cell.ResolveCellCoordinate(address, out this.column, out this.row, out this.type);
67 }
68
74 public Address(string address, Cell.AddressType type)
75 {
76 this.type = type;
77 Cell.ResolveCellCoordinate(address, out this.column, out this.row);
78 }
79
84 public string GetAddress()
85 {
87 }
88
93 public string GetColumn()
94 {
96 }
97
102 public override string ToString()
103 {
104 return GetAddress();
105 }
106
112 public bool Equals(Address other)
113 {
114 if (Row == other.Row && Column == other.Column && Type == other.Type)
115 { return true; }
116
117 return false;
118 }
119
125 public override bool Equals(object obj)
126 {
127 if (!(obj is Address))
128 {
129 return false;
130 }
131 return Equals((Address)obj);
132 }
133
138 public override int GetHashCode()
139 {
140 return ToString().GetHashCode();
141 }
142
143 // Operator overloads
151 public static bool operator ==(Address address1, Address address2)
152 {
153 return address1.Equals(address2);
154 }
155
164 public static bool operator !=(Address address1, Address address2)
165 {
166 return !address1.Equals(address2);
167 }
168
174 public int CompareTo(Address other)
175 {
176 long thisCoordinate = (long)Column * (long)Worksheet.MaxRowNumber + Row;
177 long otherCoordinate = (long)other.Column * (long)Worksheet.MaxRowNumber + other.Row;
178 return thisCoordinate.CompareTo(otherCoordinate);
179 }
180
187 public static bool operator <(Address left, Address right)
188 {
189 return left.CompareTo(right) < 0;
190 }
191
198 public static bool operator <=(Address left, Address right)
199 {
200 return left.CompareTo(right) <= 0;
201 }
202
209 public static bool operator >(Address left, Address right)
210 {
211 return left.CompareTo(right) > 0;
212 }
213
220 public static bool operator >=(Address left, Address right)
221 {
222 return left.CompareTo(right) >= 0;
223 }
224
229 internal Address Copy()
230 {
231 return new Address(this.Column, this.Row, this.Type);
232 }
233 }
234
235}
Class representing a cell of a worksheet.
Definition Cell.cs:24
static Address ResolveCellCoordinate(string address)
Gets the column and row number (zero based) of a cell by the address.
Definition Cell.cs:742
static void ValidateRowNumber(int row)
Validates the passed (zero-based) row number. An exception will be thrown if the row is invalid.
Definition Cell.cs:928
static string ResolveCellAddress(int column, int row, AddressType type=AddressType.Default)
Gets the address of a cell by the column and row number (zero based).
Definition Cell.cs:718
AddressType
Enum for the referencing style of the address.
Definition Cell.cs:60
static void ValidateColumnNumber(int column)
Validates the passed (zero-based) column number. An exception will be thrown if the column is invalid...
Definition Cell.cs:914
static string ResolveColumnAddress(int columnNumber)
Gets the column address (A - XFD).
Definition Cell.cs:867
static readonly int MaxRowNumber
Maximum row number (zero-based) as constant.
Definition Worksheet.cs:74
Struct representing the cell address as column and row (zero based).
Definition Address.cs:16
int CompareTo(Address other)
Compares two addresses using the column and row numbers.
Definition Address.cs:174
static bool operator<(Address left, Address right)
Determines whether one specified Address is less/smaller than another specified Address.
Definition Address.cs:187
Address(string address, Cell.AddressType type)
Constructor with address as string. All referencing modifiers ($) are ignored and only the defined re...
Definition Address.cs:74
Address(string address)
Constructor with address as string. If no referencing modifiers ($) are defined, the address is of re...
Definition Address.cs:64
static bool operator!=(Address address1, Address address2)
Determines whether two Address instances are not equal.
Definition Address.cs:164
override bool Equals(object obj)
Compares two objects whether they are addresses and equal.
Definition Address.cs:125
int Row
Row number (zero based).
Definition Address.cs:28
static bool operator==(Address address1, Address address2)
Determines whether two Address instances are equal.
Definition Address.cs:151
override int GetHashCode()
Gets the hash code based on the string representation of the address.
Definition Address.cs:138
override string ToString()
Overwritten ToString method.
Definition Address.cs:102
static bool operator>=(Address left, Address right)
Determines whether one specified Address is greater/larger or equal than another specified Address.
Definition Address.cs:220
Address(int column, int row)
Constructor with row and column as arguments. The referencing type of the address is default (e....
Definition Address.cs:40
Address(int column, int row, Cell.AddressType type)
Constructor with row and column as arguments. All referencing modifiers ($) are ignored and only the ...
Definition Address.cs:51
static bool operator<=(Address left, Address right)
Determines whether one specified Address is less/smaller or equal than another specified Address.
Definition Address.cs:198
string GetColumn()
Gets the column address (A - XFD).
Definition Address.cs:93
Cell.AddressType Type
Referencing type of the address.
Definition Address.cs:33
string GetAddress()
Returns the combined Address.
Definition Address.cs:84
bool Equals(Address other)
Compares two addresses whether they are equal.
Definition Address.cs:112
static bool operator>(Address left, Address right)
Determines whether one specified Address is greater/larger than another specified Address.
Definition Address.cs:209
int Column
Column number (zero based).
Definition Address.cs:24