NanoXLSX.Formatting 3.2.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.Collections.Generic;
9using NanoXLSX.Interfaces;
10using NanoXLSX.Interfaces.Reader;
11using NanoXLSX.Registry;
12using NanoXLSX.Registry.Attributes;
13
15{
16 [NanoXlsxQueuePlugIn(PlugInUUID = "FORMATTED_TEXT_SHARED_STRINGS_REPLACER", QueueUUID = PlugInUUID.FinalizingInlineProcessor, PlugInOrder = 1000)]
17 internal class SharedStringsReplacer : IPluginInlineReadProcessor
18 {
19 #region properties
23 public IOptions Options { get; set; }
27 public Workbook Workbook { get; set; }
28 #endregion
29
30 #region methods
37 public void Init(Workbook workbook, IOptions readerOptions, int? index = null)
38 {
39 this.Workbook = workbook;
40 this.Options = readerOptions;
41 }
42
46 public void Execute()
47 {
48 Dictionary<string, FormattedText> formattedTexts = Workbook.AuxiliaryData.GetData<Dictionary<string, FormattedText>>(PlugInUUID.SharedStringsReader, FormattedSharedStringsReader.AUXILIARY_DATA_ID);
49 if (formattedTexts == null)
50 {
51 return;
52 }
53 for (int i = 0; i < Workbook.Worksheets.Count; i++)
54 {
55 Worksheet sheet = Workbook.Worksheets[i];
56 foreach (KeyValuePair<string, FormattedText> entry in formattedTexts)
57 {
58 List<Cell> cells = sheet.CellsByValue(entry.Key);
59 if (cells != null && cells.Count > 0)
60 {
61 foreach (Cell cell in cells)
62 {
63 sheet.Cells[cell.CellAddress].Value = entry.Value;
64 }
65 }
66 }
67 }
68 }
69 #endregion
70 }
71}