Ejemplo n.º 1
0
        public static CT_Rst Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            CT_Rst ctObj = new CT_Rst();

            ctObj.r   = new List <CT_RElt>();
            ctObj.rPh = new List <CT_PhoneticRun>();
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "phoneticPr")
                {
                    ctObj.phoneticPr = CT_PhoneticPr.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "r")
                {
                    ctObj.r.Add(CT_RElt.Parse(childNode, namespaceManager));
                }
                else if (childNode.LocalName == "rPh")
                {
                    ctObj.rPh.Add(CT_PhoneticRun.Parse(childNode, namespaceManager));
                }
                else if (childNode.LocalName == "t")
                {
                    ctObj.t = childNode.InnerText.Replace("\r", "");
                }
            }
            return(ctObj);
        }
Ejemplo n.º 2
0
        public static SstDocument Parse(XmlDocument xml, XmlNamespaceManager namespaceManager)
        {
            try
            {
                SstDocument sstDoc = new SstDocument();
                sstDoc.AddNewSst();
                CT_Sst sst = sstDoc.GetSst();
                sst.count       = XmlHelper.ReadInt(xml.DocumentElement.Attributes["count"]);
                sst.uniqueCount = XmlHelper.ReadInt(xml.DocumentElement.Attributes["uniqueCount"]);

                XmlNodeList nl = xml.SelectNodes("//d:sst/d:si", namespaceManager);
                if (nl != null)
                {
                    foreach (XmlNode node in nl)
                    {
                        CT_Rst rst = CT_Rst.Parse(node, namespaceManager);
                        sstDoc.sst.si.Add(rst);
                    }
                }
                return(sstDoc);
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }
Ejemplo n.º 3
0
        private CT_PhoneticPr phoneticPrField = null; // optional field 

        public void Set(CT_Rst o)
        {
            this.tField = o.tField;
            this.rField = o.rField;
            this.rPhField = o.rPhField;
            this.phoneticPrField = o.phoneticPrField;
        }
Ejemplo n.º 4
0
        private CT_PhoneticPr phoneticPrField = null;  // optional field

        public void Set(CT_Rst o)
        {
            this.tField          = o.tField;
            this.rField          = o.rField;
            this.rPhField        = o.rPhField;
            this.phoneticPrField = o.phoneticPrField;
        }
Ejemplo n.º 5
0
 //public CT_Cell()
 //{
 //    this.extLstField = new CT_ExtensionList();
 //    //this.isField = new CT_Rst();
 //    //this.fField = new CT_CellFormula();
 //    this.sField = (uint)(0);
 //    this.tField = ST_CellType.n;
 //    this.cmField = ((uint)(0));
 //    this.vmField = ((uint)(0));
 //    this.phField = false;
 //}
 public void Set(CT_Cell cell)
 {
     fField      = cell.fField;
     vField      = cell.vField;
     isField     = cell.isField;
     extLstField = cell.extLstField;
     rField      = cell.rField;
     sField      = cell.sField;
     tField      = cell.tField;
     cmField     = cell.cmField;
     vmField     = cell.vmField;
     phField     = cell.phField;
 }
Ejemplo n.º 6
0
 //public CT_Cell()
 //{
 //    this.extLstField = new CT_ExtensionList();
 //    //this.isField = new CT_Rst();
 //    //this.fField = new CT_CellFormula();
 //    this.sField = (uint)(0);
 //    this.tField = ST_CellType.n;
 //    this.cmField = ((uint)(0));
 //    this.vmField = ((uint)(0));
 //    this.phField = false;
 //}
 public void Set(CT_Cell cell)
 {
     fField = cell.fField;
     vField = cell.vField;
     isField = cell.isField;
     extLstField = cell.extLstField;
     rField = cell.rField;
     sField = cell.sField;
     tField = cell.tField;
     cmField = cell.cmField;
     vmField = cell.vmField;
     phField = cell.phField;
 }
Ejemplo n.º 7
0
        public static SstDocument Parse(XmlDocument xml, XmlNamespaceManager namespaceManager)
        {

            try
            {
                SstDocument sstDoc=new SstDocument();
                sstDoc.AddNewSst();

                XmlNodeList nl = xml.SelectNodes("//d:sst/d:si", namespaceManager);
                if (nl != null)
                {
                    foreach (XmlNode node in nl)
                    {
                        XmlNode n = node.SelectSingleNode("d:t", namespaceManager);
                        CT_Rst rst = new CT_Rst();
                        rst.XmlText = node.InnerXml;
                        if (n != null)
                        {
                            rst.t = n.InnerText;
                        }
                        else
                        {
                            XmlNodeList tNodes = node.SelectNodes(".//d:t", namespaceManager);
                            if (tNodes != null)
                            {
                                rst.r = new System.Collections.Generic.List<CT_RElt>();

                                foreach (XmlNode tNode in tNodes)
                                {
                                    CT_RElt relt = new CT_RElt();
                                    relt.t = tNode.InnerText;
                                    rst.r.Add(relt);
                                }
                            }
                        }
                        sstDoc.sst.si.Add(rst);
                    }
                }
                return sstDoc;
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }        /// <summary>
Ejemplo n.º 8
0
        public static CommentsDocument Parse(XmlDocument xmlDoc, XmlNamespaceManager NameSpaceManager)
        {
            CommentsDocument commentsDoc = new CommentsDocument();

            commentsDoc.comments = new CT_Comments();
            foreach (XmlElement node in xmlDoc.SelectNodes("//d:authors/d:author", NameSpaceManager))
            {
                commentsDoc.comments.authors.AddAuthor(node.InnerText);
            }
            foreach (XmlElement node in xmlDoc.SelectNodes("//d:commentList/d:comment", NameSpaceManager))
            {
                CT_Comment comment = commentsDoc.comments.commentList.AddNewComment();
                comment.authorId = uint.Parse(node.GetAttribute("authorId"));
                comment.@ref     = node.GetAttribute("ref");
                comment.text     = CT_Rst.Parse(node.ChildNodes[0], NameSpaceManager);
            }
            return(commentsDoc);
        }
Ejemplo n.º 9
0
        public static SstDocument Parse(XmlDocument xml, XmlNamespaceManager namespaceManager)
        {
            try
            {
                SstDocument sstDoc = new SstDocument();
                sstDoc.AddNewSst();

                XmlNodeList nl = xml.SelectNodes("//d:sst/d:si", namespaceManager);
                if (nl != null)
                {
                    foreach (XmlNode node in nl)
                    {
                        XmlNode n   = node.SelectSingleNode("d:t", namespaceManager);
                        CT_Rst  rst = new CT_Rst();
                        rst.XmlText = node.InnerXml;
                        if (n != null)
                        {
                            rst.t = n.InnerText;
                        }
                        else
                        {
                            XmlNodeList tNodes = node.SelectNodes(".//d:t", namespaceManager);
                            if (tNodes != null)
                            {
                                rst.r = new System.Collections.Generic.List <CT_RElt>();

                                foreach (XmlNode tNode in tNodes)
                                {
                                    CT_RElt relt = new CT_RElt();
                                    relt.t = tNode.InnerText;
                                    rst.r.Add(relt);
                                }
                            }
                        }
                        sstDoc.sst.si.Add(rst);
                    }
                }
                return(sstDoc);
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }        /// <summary>
Ejemplo n.º 10
0
        public static CT_Cell Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Cell ctObj = new CT_Cell();

            ctObj.r = XmlHelper.ReadString(node.Attributes["r"]);
            ctObj.s = XmlHelper.ReadUInt(node.Attributes["s"]);
            if (node.Attributes["t"] != null)
            {
                ctObj.t = (ST_CellType)Enum.Parse(typeof(ST_CellType), node.Attributes["t"].Value);
            }
            ctObj.cm = XmlHelper.ReadUInt(node.Attributes["cm"]);
            ctObj.vm = XmlHelper.ReadUInt(node.Attributes["vm"]);
            ctObj.ph = XmlHelper.ReadBool(node.Attributes["ph"]);
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "f")
                {
                    ctObj.f = CT_CellFormula.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "v")
                {
                    ctObj.v = childNode.InnerText;
                }
                else if (childNode.LocalName == "is")
                {
                    ctObj.@is = CT_Rst.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "extLst")
                {
                    ctObj.extLst = CT_ExtensionList.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Ejemplo n.º 11
0
        private string guidField = null;         // optional attribute

        //public CT_Comment()
        //{
        //    this.textField = new CT_Rst();
        //}
        public static CT_Comment Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Comment ctObj = new CT_Comment();

            ctObj.@ref = XmlHelper.ReadString(node.Attributes["ref"]);
            if (node.Attributes["authorId"] != null)
            {
                ctObj.authorId = XmlHelper.ReadUInt(node.Attributes["authorId"]);
            }
            ctObj.guid = XmlHelper.ReadString(node.Attributes["guid"]);
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "text")
                {
                    ctObj.text = CT_Rst.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Ejemplo n.º 12
0
        public void GetCellComment()
        {
            CommentsTable sheetComments = new CommentsTable();

            CT_Comments comments = sheetComments.GetCTComments();
            CT_CommentList commentList = comments.commentList;

            // Create 2 comments for A1 and A" cells
            CT_Comment comment0 = commentList.InsertNewComment(0);
            comment0.@ref = "A1";
            CT_Rst ctrst0 = new CT_Rst();
            ctrst0.t = (TEST_A1_TEXT);
            comment0.text = (ctrst0);
            CT_Comment comment1 = commentList.InsertNewComment(0);
            comment1.@ref = ("A2");
            CT_Rst ctrst1 = new CT_Rst();
            ctrst1.t = (TEST_A2_TEXT);
            comment1.text = (ctrst1);

            // Test Finding the right comment for a cell
            Assert.AreSame(comment0, sheetComments.GetCTComment("A1"));
            Assert.AreSame(comment1, sheetComments.GetCTComment("A2"));
            Assert.IsNull(sheetComments.GetCTComment("A3"));
        }
Ejemplo n.º 13
0
 /**
  * Create a rich text string
  */
 public XSSFRichTextString(String str)
 {
     st = new CT_Rst();
     st.t = str;
     PreserveSpaces(st.t);
 }
Ejemplo n.º 14
0
        public void TestUtfDecode()
        {
            CT_Rst st = new CT_Rst();
            st.t = ("abc_x000D_2ef_x000D_");
            XSSFRichTextString rt = new XSSFRichTextString(st);
            //_x000D_ is Converted into carriage return
            Assert.AreEqual("abc\r2ef\r", rt.String);

        }
Ejemplo n.º 15
0
 public void unsetIs()
 {
     this.isField = null;
 }
Ejemplo n.º 16
0
        public void TestCreateNew()
        {
            SharedStringsTable sst = new SharedStringsTable();

            CT_Rst st;
            int idx;

            // Check defaults
            Assert.IsNotNull(sst.Items);
            Assert.AreEqual(0, sst.Items.Count);
            Assert.AreEqual(0, sst.Count);
            Assert.AreEqual(0, sst.UniqueCount);

            st = new CT_Rst();
            st.t = ("Hello, World!");

            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(1, sst.Count);
            Assert.AreEqual(1, sst.UniqueCount);

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(2, sst.Count);
            Assert.AreEqual(1, sst.UniqueCount);

            //and again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(3, sst.Count);
            Assert.AreEqual(1, sst.UniqueCount);

            st = new CT_Rst();
            st.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(4, sst.Count);
            Assert.AreEqual(2, sst.UniqueCount);

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(5, sst.Count);
            Assert.AreEqual(2, sst.UniqueCount);

            st = new CT_Rst();
            CT_RElt r = st.AddNewR();
            CT_RPrElt pr = r.AddNewRPr();
            pr.AddNewColor().SetRgb(new byte[] { (byte)0xFF, 0, 0 }); //red
            pr.AddNewI().val = (true);  //bold
            pr.AddNewB().val = (true);  //italic
            r.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(6, sst.Count);
            Assert.AreEqual(3, sst.UniqueCount);

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(7, sst.Count);
            Assert.AreEqual(3, sst.UniqueCount);

            //OK. the sst table is Filled, check the contents
            Assert.AreEqual(3, sst.Items.Count);
            Assert.AreEqual("Hello, World!", new XSSFRichTextString(sst.GetEntryAt(0)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(1)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(2)).ToString());
        }
Ejemplo n.º 17
0
 public static CT_Rst Parse(XmlNode xmlNode, XmlNamespaceManager namespaceManager)
 {
     CT_Rst rst = new CT_Rst();
     rst.r = new List<CT_RElt>();
     var rNodes = xmlNode.SelectNodes("d:r", namespaceManager);
     foreach (XmlNode rNode in rNodes)
     {
         CT_RElt relt = rst.AddNewR();
         var rPrNode = rNode.SelectSingleNode("d:rPr", namespaceManager);
         if (rPrNode != null)
         {
             CT_RPrElt rprelt = relt.AddNewRPr();
             foreach (XmlNode childNode in rPrNode.ChildNodes)
             {
                 switch (childNode.Name)
                 { 
                     case "b":
                         CT_BooleanProperty bprop= rprelt.AddNewB();
                         bprop.val = true;
                         break;
                     case "i":
                         CT_BooleanProperty iprop = rprelt.AddNewI();
                         iprop.val = true;
                         break;
                     case "u":
                         CT_UnderlineProperty uProp = rprelt.AddNewU();
                         uProp.val = (ST_UnderlineValues)Enum.Parse(typeof(ST_UnderlineValues), childNode.Attributes["val"].Value);
                         break;
                     case "color":
                         CT_Color color = rprelt.AddNewColor();
                         if(childNode.Attributes["theme"]!=null)
                             color.theme = uint.Parse(childNode.Attributes["theme"].Value);
                         if(childNode.Attributes["auto"]!=null)
                             color.auto = childNode.Attributes["auto"].Value=="1"?true:false;
                         if(childNode.Attributes["indexed"]!=null)
                             color.indexed = uint.Parse(childNode.Attributes["indexed"].Value);
                         if(childNode.Attributes["tint"]!=null)
                             color.tint = Double.Parse(childNode.Attributes["tint"].Value);
                         break;
                     case "rFont":
                         CT_FontName fontname = rprelt.AddNewRFont();
                         fontname.val = childNode.Attributes["val"].Value;
                         break;
                     case "family":
                         CT_IntProperty familyProp = rprelt.AddNewFamily();
                         familyProp.val = Int32.Parse(childNode.Attributes["val"].Value);
                         break;
                     case "charset":
                         CT_IntProperty charsetProp = rprelt.AddNewCharset();
                         charsetProp.val = Int32.Parse(childNode.Attributes["val"].Value);
                         break;
                     case "scheme":
                         CT_FontScheme schemeProp = rprelt.AddNewScheme();
                         schemeProp.val = (ST_FontScheme)Enum.Parse(typeof(ST_FontScheme), childNode.Attributes["val"].Value);
                         break;
                     case "sz":
                         CT_FontSize szProp = rprelt.AddNewSz();
                         szProp.val = Int32.Parse(childNode.Attributes["val"].Value);
                         break;
                     case "vertAlign":
                         CT_VerticalAlignFontProperty vertAlignProp = rprelt.AddNewVertAlign();
                         vertAlignProp.val = (ST_VerticalAlignRun)Enum.Parse(typeof(ST_VerticalAlignRun), childNode.Attributes["val"].Value);
                         break;
                 }
             }
         }
         var tNode = rNode.SelectSingleNode("d:t", namespaceManager);
         relt.t = tNode.InnerText.Replace("\r","");
     }
     return rst;
 }
Ejemplo n.º 18
0
 public static CT_Rst Parse(XmlNode node, XmlNamespaceManager namespaceManager)
 {
     CT_Rst ctObj = new CT_Rst();
     ctObj.r = new List<CT_RElt>();
     ctObj.rPh = new List<CT_PhoneticRun>();
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.LocalName == "phoneticPr")
             ctObj.phoneticPr = CT_PhoneticPr.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "r")
             ctObj.r.Add(CT_RElt.Parse(childNode, namespaceManager));
         else if (childNode.LocalName == "rPh")
             ctObj.rPh.Add(CT_PhoneticRun.Parse(childNode, namespaceManager));
         else if (childNode.LocalName == "t")
             ctObj.t = childNode.InnerText.Replace("\r", "");
     }
     return ctObj;
 }
Ejemplo n.º 19
0
 /**
  * Create empty rich text string and Initialize it with empty string
  */
 public XSSFRichTextString()
 {
     st = new CT_Rst();
 }
Ejemplo n.º 20
0
 public void unsetIs()
 {
     this.isField = null;
 }
Ejemplo n.º 21
0
 /**
  * Create a rich text string from the supplied XML bean
  */
 public XSSFRichTextString(CT_Rst st)
 {
     this.st = st;
 }
Ejemplo n.º 22
0
        internal SortedDictionary<int, CT_RPrElt> GetFormatMap(CT_Rst entry)
        {
            int length = 0;
            SortedDictionary<int, CT_RPrElt> formats = new SortedDictionary<int, CT_RPrElt>();
            foreach (CT_RElt r in entry.r)
            {
                String txt = r.t;
                CT_RPrElt fmt = r.rPr;

                length += txt.Length;
                formats[length] = fmt;
            }
            return formats;
        }
Ejemplo n.º 23
0
 CT_Rst buildCTRst(String text, SortedDictionary<int, CT_RPrElt> formats)
 {
     if (text.Length != GetLastKey(formats.Keys))
     {
         throw new ArgumentException("Text length was " + text.Length +
                 " but the last format index was " + GetLastKey(formats.Keys));
     }
     CT_Rst st = new CT_Rst();
     int runStartIdx = 0;
     for (SortedDictionary<int, CT_RPrElt>.KeyCollection.Enumerator it = formats.Keys.GetEnumerator(); it.MoveNext(); )
     {
         int runEndIdx = it.Current;
         CT_RElt run = st.AddNewR();
         String fragment = text.Substring(runStartIdx, runEndIdx - runStartIdx);
         run.t = (fragment);
         PreserveSpaces(run.t);
         CT_RPrElt fmt = formats[runEndIdx];
         if (fmt != null)
             run.rPr = (fmt);
         runStartIdx = runEndIdx;
     }
     return st;
 }