NanoXLSX.Compatibility 3.2.0
Loading...
Searching...
No Matches
ExternalLinkBuilder.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;
9using static NanoXLSX.ExternalCellValue;
10
11namespace NanoXLSX
12{
18 {
19 private readonly ExternalLink externalLink;
20 private ExternalWorksheet currentWorksheet;
21
27 public ExternalLinkBuilder(string absoluteUri, string relativeUri = null)
28 {
29 ExternalLink externalLink = new ExternalLink(absoluteUri, relativeUri);
30 this.externalLink = externalLink;
31 }
32
38 internal ExternalLinkBuilder(ExternalLink externalLink)
39 {
40 this.externalLink = externalLink ?? throw new ArgumentException("The external link cannot be null");
41 }
42
48 {
49 return externalLink;
50 }
51
58 {
59 ExternalWorksheet worksheet = new ExternalWorksheet(name);
60
61 externalLink.AddWorksheet(worksheet);
62 currentWorksheet = worksheet;
63
64 return this;
65 }
66
72 {
73 currentWorksheet = externalLink.GetWorksheet(name);
74 return this;
75 }
76
86 public ExternalLinkBuilder AddCell(string address, string value)
87 {
88 EnsureCurrentWorksheet();
89 currentWorksheet.AddCell(address, value);
90
91 return this;
92 }
93
104 public ExternalLinkBuilder AddCell(string address, string value, ExternalCellValue.DataType type)
105 {
106 EnsureCurrentWorksheet();
107 currentWorksheet.AddCell(address, value, type);
108 return this;
109 }
110
114 private void EnsureCurrentWorksheet()
115 {
116 if (currentWorksheet == null)
117 {
118 throw new ArgumentException(
119 "No external worksheet is currently selected. " +
120 "Call AddWorksheet or UseWorksheet before adding cell data.");
121 }
122 }
123
124 }
125}
Represents a cached cell of an external worksheet with an optional type.
DataType
Enum for the data type of the external cell.
ExternalLinkBuilder UseWorksheet(string name)
Selects an already declared external worksheet. The worksheet will be marked as currently used worksh...
ExternalLinkBuilder AddCell(string address, string value)
Adds or replaces a cached cell value (string representation) on the current worksheet.
ExternalLinkBuilder(string absoluteUri, string relativeUri=null)
Constructor with mandatory absolute URI and optional relative URI.
ExternalLinkBuilder AddWorksheet(string name)
Adds a worksheet to the external workbook definition and marks it as currently used worksheet in the ...
ExternalLinkBuilder AddCell(string address, string value, ExternalCellValue.DataType type)
Adds or replaces a cached cell value with specified type on the current worksheet.
ExternalLink Build()
Returns the configured external workbook link.
Represents a worksheet declared by an external workbook link.