NanoXLSX.Compatibility 3.2.0
Loading...
Searching...
No Matches
ExternalWorksheet.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 NanoXLSX.Utils;
9using System;
10using System.Collections.Generic;
11using System.Collections.ObjectModel;
12using static NanoXLSX.ExternalCellValue;
13
14namespace NanoXLSX
15{
19 public class ExternalWorksheet
20 {
21
25 private readonly Dictionary<Address, ExternalCellValue> cells = new Dictionary<Address, ExternalCellValue>();
26
27
31 public ReadOnlyDictionary<Address, ExternalCellValue> Cells
32 {
33 get { return new ReadOnlyDictionary<Address, ExternalCellValue>(cells); }
34 }
35
39 public string Name { get; }
40
44 internal bool? RefreshErros { get; set; }
45
50 public ExternalWorksheet(string name)
51 {
52 Validators.ValidateWorksheetName(name);
53 Name = name;
54 }
55
63 public ExternalWorksheet AddCell(string address, string value)
64 {
65 return AddCell(address, value, ExternalCellValue.DataType.String);
66 }
67
78 public ExternalWorksheet AddCell(string address, string value, ExternalCellValue.DataType type)
79 {
80 Validators.ValidateCellAddressExpression(address, Cell.AddressScope.SingleAddress);
81 cells[new Address(address)] = new ExternalCellValue(value, type);
82 return this;
83
84 }
85
97 internal void AddCell(string address, string value, ExternalCellValue.DataType type, string cellMetaData)
98 {
99 AddCell(address, value, type);
100 if (cellMetaData != null)
101 {
102 cells[new Address(address)].CellMetadata = ParserUtils.ParseInt(cellMetaData);
103 }
104 }
105
110 public bool RemoveCell(string address)
111 {
112 Validators.ValidateCellAddressExpression(address, Cell.AddressScope.SingleAddress);
113 return cells.Remove(new Address(address));
114 }
115
121 public bool TryGetCell(string address, out ExternalCellValue cell)
122 {
123 try
124 {
125 return cells.TryGetValue(new Address(address), out cell);
126 }
127 catch (Exception)
128 {
129 cell = null;
130 return false;
131 }
132 }
133 }
134}
Represents a cached cell of an external worksheet with an optional type.
DataType
Enum for the data type of the external cell.
string Name
Gets the name of the external worksheet.
ExternalWorksheet AddCell(string address, string value, ExternalCellValue.DataType type)
Adds or replaces a cached cell value with defined typ.
ReadOnlyDictionary< Address, ExternalCellValue > Cells
Gets the dictionary on external cells, where the Address is the key and ExternalCellValue is the valu...
ExternalWorksheet AddCell(string address, string value)
Adds or replaces a cached cell value.
bool RemoveCell(string address)
Removes cached data for a cell.
ExternalWorksheet(string name)
Constructor with name.
bool TryGetCell(string address, out ExternalCellValue cell)
Tries to get cached data for a cell.