Пример #1
0
        /// <summary>
        /// Sets the text of this text run.in the
        /// </summary>
        /// <param name="value">the literal text which shall be displayed in the document</param>
        /// <param name="pos">position in the text array (NB: 0 based)</param>
        private XWPFSharedRun SetText(String value, int pos)
        {
            int length = run.SizeOfTArray();

            if (pos > length)
            {
                throw new IndexOutOfRangeException("Value too large for the parameter position");
            }
            CT_Text1 t = (pos < length && pos >= 0) ? run.GetTArray(pos) : run.AddNewT();

            t.Value = (value);
            preserveSpaces(t);
            return(this);
        }
Пример #2
0
        public void TestWhitespace()
        {
            String[]
            text = new String[] {
                "  The quick brown fox",
                "\t\tjumped over the lazy dog"
            };
            MemoryStream bos = new MemoryStream();
            XWPFDocument doc = new XWPFDocument();

            foreach (String s in text)
            {
                XWPFParagraph p1 = doc.CreateParagraph();
                XWPFRun       r1 = p1.CreateRun();
                r1.SetText(s);
            }
            doc.Write(bos);

            MemoryStream bis  = new MemoryStream(bos.ToArray());
            var          doc2 = new XWPFDocument(bis);

            var paragraphs = doc2.Paragraphs;

            Assert.AreEqual(2, paragraphs.Count);
            for (int i = 0; i < text.Length; i++)
            {
                XWPFParagraph p1       = paragraphs[i];
                String        expected = text[i];
                Assert.AreEqual(expected, p1.Text);
                CT_P    ctp    = p1.GetCTP();
                CT_R    ctr    = ctp.GetRArray(0);
                CT_Text ctText = ctr.GetTArray(0);
                // if text has leading whitespace then expect xml-fragment to have xml:space="preserve" set
                // <xml-fragment xml:space="preserve" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
                bool isWhitespace = Character.isWhitespace(expected[0]);
                Assert.AreEqual(isWhitespace, ctText.space == "preserve");
            }
        }
Пример #3
0
 /**
  * Return the string content of this text run
  *
  * @return the text of this text run.or <code>null</code> if not Set
  */
 public String GetText(int pos)
 {
     return(run.SizeOfTArray() == 0 ? null : run.GetTArray(pos).Value);
 }