/// <summary> /// Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces /// </summary> /// <param name="xs">the string to check</param> static void preserveSpaces(CT_Text1 xs) { String text = xs.Value; if (text != null && (text.StartsWith(" ") || text.EndsWith(" "))) { // XmlCursor c = xs.NewCursor(); // c.ToNextToken(); // c.InsertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); // c.Dispose(); xs.space = "preserve"; } }
/// <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); }