Пример #1
0
        private void LoadStringtable(WorkbookPart workbook)
        {
            SharedStringTablePart part = workbook.SharedStringTablePart;

            using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read))
            {
                _stringtable = new XmlDocument();
                _stringtable.Load(s);
            }
        }
Пример #2
0
 public static void WriteStringTable(SharedStringTablePart sharedStringTablePart, StringKeyList items)
 {
     using (var writer = XmlWriter.Create(sharedStringTablePart.GetStream(FileMode.Create)
                                          , new XmlWriterSettings {
         Encoding = Encoding.UTF8, CloseOutput = true
     }))
     {
         writer.WriteStartDocument();
         WriteStartElement(writer, new Excel.SharedStringTable {
             Count = (uint)items.Count
         });
         foreach (var item in items)
         {
             WriteElement(writer, item.Value);
         }
         writer.WriteEndElement();
         writer.WriteEndDocument();
         writer.Flush();
     }
 }
Пример #3
0
        /// <summary>
        /// Dumps collected shared strings into package
        /// </summary>
        /// <param name="ss"></param>
        private void WriteSharedStrings(SharedStringTablePart ss)
        {
            using (var wss = System.Xml.XmlWriter.Create(ss.GetStream(System.IO.FileMode.Create, System.IO.FileAccess.Write)))
            {
                wss.WriteStartDocument();


                wss.WriteStartElement("sst", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
                //add unique and count later
                wss.WriteAttributeString("uniqueCount", strings.Count.ToString());
                wss.WriteAttributeString("count", totalStringsCount.ToString());
                foreach (var s in strings)
                {
                    wss.WriteStartElement("si");
                    wss.WriteStartElement("t");
                    wss.WriteValue(s);
                    wss.WriteEndElement();
                    wss.WriteEndElement();
                }

                wss.WriteEndElement();
                wss.WriteEndDocument();

                //<?xml version="1.0" encoding="UTF-8" standalone="true"?>
                //-<sst uniqueCount="4" count="5" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
                //-<si>
                //<t>date</t>
                //</si>
                //-<si>
                //<t>bool</t>
                //</si>
                //-<si>
                //<t>string</t>
                //</si>
                //-<si>
                //<t>num</t>
                //</si>
                //</sst>
            }
        }