NanoXLSX.Writer 3.2.1
Loading...
Searching...
No Matches
CompatibilityProcessor.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.Exceptions;
9using NanoXLSX.Interfaces.Writer;
10using NanoXLSX.Registry;
11using System;
12
14{
21 internal class CompatibilityProcessor : IPluginWriteProcessor
22 {
26 public IWriteContext WriteContext { get; set; }
30 public Action<IWriteContext, string> InlinePluginHandler { get; set; }
31
37 public void Init(IWriteContext context, Action<IWriteContext, string> inlinePluginHandler)
38 {
39 this.WriteContext = context;
40 this.InlinePluginHandler = inlinePluginHandler;
41 }
42
46 public void Execute()
47 {
48 // Possible injected compatibility checks or changes (e.g. enabling a feature by a plug-in)
49 this.InlinePluginHandler?.Invoke(this.WriteContext, PlugInUUID.CompatibilityInlineProcessor); // DO NOT MOVE THIS TO THE END
50 // -------------------------------------------
51 CheckExternalLinks();
52
53 // TODO add further compatibility checks of the core scope (in fo plug-ins are loaded) here
54 }
55
56 private void CheckExternalLinks()
57 {
58 bool externalLinksExist = WriteContext.Workbook.Features.ContainsExternalLinks;
59 if (externalLinksExist && !WriteContext.IsFeaturePrepared(PlugInUUID.WriteExternalLinkFeature))
60 {
61 throw new NotSupportedContentException("The workbook contains external links in defined names or cell formulas, but no compatible writer plug-in is capable to write such links. " +
62 "Note: Consider adding the package NanoXLSX.Compatibility. ");
63 }
64 }
65 }
66}