9using System.Collections.Generic;
11using NanoXLSX.Interfaces;
12using NanoXLSX.Interfaces.Reader;
13using NanoXLSX.Registry;
14using NanoXLSX.Registry.Attributes;
18 [NanoXlsxQueuePlugIn(PlugInUUID =
"FORMATTED_TEXT_SHARED_STRINGS_REPLACER", QueueUUID = PlugInUUID.ReaderAppendingQueue)]
19 internal class SharedStringsReplacer : IPluginQueueReader
25 public IOptions Options {
get;
set; }
29 public Workbook Workbook {
get;
set; }
33 public Action<MemoryStream, Workbook, string, IOptions, int?> InlinePluginHandler {
get;
set; }
44 public void Init(MemoryStream stream, Workbook workbook, IOptions readerOptions, Action<MemoryStream, Workbook, string, IOptions, int?> inlinePluginHandler)
46 this.Workbook = workbook;
47 this.Options = readerOptions;
48 this.InlinePluginHandler = inlinePluginHandler;
56 Dictionary<string, FormattedText> formattedTexts = Workbook.AuxiliaryData.GetData<Dictionary<string, FormattedText>>(PlugInUUID.SharedStringsReader, FormattedSharedStringsReader.AUXILIARY_DATA_ID);
57 if (formattedTexts ==
null)
61 for (
int i = 0; i < Workbook.Worksheets.Count; i++)
63 Worksheet sheet = Workbook.Worksheets[i];
64 foreach (KeyValuePair<string, FormattedText> entry
in formattedTexts)
66 List<Cell> cells = sheet.CellsByValue(entry.Key);
67 if (cells !=
null && cells.Count > 0)
69 foreach (Cell cell
in cells)
71 sheet.Cells[cell.CellAddress].Value = entry.Value;