NanoXLSX.Formatting 3.0.0
Loading...
Searching...
No Matches
SharedStringsReplacer.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 System.Collections.Generic;
10using System.IO;
11using NanoXLSX.Interfaces;
12using NanoXLSX.Interfaces.Reader;
13using NanoXLSX.Registry;
14using NanoXLSX.Registry.Attributes;
15
17{
18 [NanoXlsxQueuePlugIn(PlugInUUID = "FORMATTED_TEXT_SHARED_STRINGS_REPLACER", QueueUUID = PlugInUUID.ReaderAppendingQueue)]
19 internal class SharedStringsReplacer : IPluginQueueReader
20 {
21 #region properties
25 public IOptions Options { get; set; }
29 public Workbook Workbook { get; set; }
33 public Action<MemoryStream, Workbook, string, IOptions, int?> InlinePluginHandler { get; set; }
34 #endregion
35
36 #region methods
44 public void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions, Action<MemoryStream, Workbook, string, IOptions, int?> inlinePluginHandler)
45 {
46 this.Workbook = workbook;
47 this.Options = readerOptions;
48 this.InlinePluginHandler = inlinePluginHandler;
49 }
50
54 public void Execute()
55 {
56 Dictionary<string, FormattedText> formattedTexts = Workbook.AuxiliaryData.GetData<Dictionary<string, FormattedText>>(PlugInUUID.SharedStringsReader, FormattedSharedStringsReader.AUXILIARY_DATA_ID);
57 if (formattedTexts == null)
58 {
59 return;
60 }
61 for (int i = 0; i < Workbook.Worksheets.Count; i++)
62 {
63 Worksheet sheet = Workbook.Worksheets[i];
64 foreach (KeyValuePair<string, FormattedText> entry in formattedTexts)
65 {
66 List<Cell> cells = sheet.CellsByValue(entry.Key);
67 if (cells != null && cells.Count > 0)
68 {
69 foreach (Cell cell in cells)
70 {
71 sheet.Cells[cell.CellAddress].Value = entry.Value;
72 }
73 }
74 }
75 }
76 }
77 #endregion
78 }
79}