NanoXLSX.Writer 3.2.1
Loading...
Searching...
No Matches
SharedStringWriter.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.Interfaces;
9using NanoXLSX.Interfaces.Writer;
10using NanoXLSX.Registry;
11using NanoXLSX.Registry.Attributes;
12using NanoXLSX.Utils;
13using NanoXLSX.Utils.Xml;
14
16{
20 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.SharedStringsWriter)]
21 internal class SharedStringWriter : ISharedStringWriter
22 {
23 private XmlElement sst;
24 private SortedMap sharedStrings;
25
26 #region properties
30 public Workbook Workbook { get; set; }
31
35 public XmlElement XmlElement => sst;
36
40 public int SharedStringsTotalCount { get; set; }
41
45 public ISortedMap SharedStrings => sharedStrings;
46
47 #endregion
48 #region constructors
52 public SharedStringWriter()
53 {
54 }
55
56 #endregion
57 #region methods
62 public void Init(IBaseWriter baseWriter)
63 {
64 this.Workbook = baseWriter.Workbook;
65 sharedStrings = new SortedMap();
66 SharedStringsTotalCount = 0;
67 }
68
72 public void Execute()
73 {
74 sst = XmlElement.CreateElement("sst");
75 sst.AddDefaultXmlNameSpace("http://schemas.openxmlformats.org/spreadsheetml/2006/main");
76 sst.AddAttribute("count", ParserUtils.ToString(SharedStringsTotalCount));
77 sst.AddAttribute("uniqueCount", ParserUtils.ToString(sharedStrings.Count));
78 foreach (IFormattableText text in sharedStrings.Keys)
79 {
80 sst.AddChildElement(text.GetXmlElement());
81 }
82
83 WriterPlugInHandler.HandleInlineQueuePlugins(ref sst, Workbook, PlugInUUID.SharedStringsInlineWriter);
84 }
85 #endregion
86 }
87}