NanoXLSX.Compatibility 3.2.0
Loading...
Searching...
No Matches
WorkbookExtensions.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
9using NanoXLSX.Registry;
10using System;
11using System.Collections.Generic;
12using System.ComponentModel;
13
14namespace NanoXLSX.Extensions
15{
19 [EditorBrowsable(EditorBrowsableState.Never)]
20 public static class WorkbookExtensions
21 {
28 public static void AddExternalLink(this Workbook workbook, ExternalLink externalLink)
29 {
30 if (externalLink == null)
31 {
32 throw new ArgumentNullException(nameof(externalLink), "An external link cannot be null.");
33 }
34 IReadOnlyList<ExternalLink> externalLinks = GetExternalLinks(workbook);
35 int index = externalLinks.Count;
36 while (workbook.AuxiliaryData.GetData<ExternalLink>(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY, index) != null)
37 {
38 index++;
39 }
40 workbook.AuxiliaryData.SetData(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY, index, externalLink, true);
41 }
42
51 public static ExternalLink AddExternalLink(this Workbook workbook, ExternalLinkBuilder builder)
52 {
53 if (builder == null)
54 {
55 throw new ArgumentNullException(nameof(builder), "A builder for external link cannot be null.");
56 }
57 ExternalLink externalLink = builder.Build();
58 AddExternalLink(workbook, externalLink);
59 return externalLink;
60 }
61
67 public static IReadOnlyList<ExternalLink> GetExternalLinks(this Workbook workbook)
68 {
69 return workbook.AuxiliaryData.GetDataList<ExternalLink>(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY);
70 }
71
78 public static bool RemoveExternalLink(this Workbook workbook, ExternalLink externalLink)
79 {
80 return workbook.AuxiliaryData.RemoveEntityData(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY, externalLink);
81 }
82
87 public static void ClearExternalLinks(this Workbook workbook)
88 {
89 workbook.AuxiliaryData.ClearEntityData(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY);
90 }
91
92 }
93}
Writer extension methods for the Workbook class.
static bool RemoveExternalLink(this Workbook workbook, ExternalLink externalLink)
Removes a specific external link from the workbook.
static IReadOnlyList< ExternalLink > GetExternalLinks(this Workbook workbook)
Gets all external links of the workbook.
static ExternalLink AddExternalLink(this Workbook workbook, ExternalLinkBuilder builder)
Adds an external link to the workbook, using a builder.
static void ClearExternalLinks(this Workbook workbook)
Removes all external links from the workbook.
static void AddExternalLink(this Workbook workbook, ExternalLink externalLink)
Adds an external link to the workbook.
Provides a fluent API for defining worksheets and cached cell values of an external workbook link.
ExternalLink Build()
Returns the configured external workbook link.