Open XML: выравнивание текста с отступом - PullRequest
0 голосов
/ 29 июня 2018

На изображении текст с номерами второй строки выравнивается по 6. вместо соответственно.

enter image description here

Я пишу текст в текстовый документ, используя текстовый редактор Open XML. Всякий раз, когда у меня есть отступ, текст не выравнивается должным образом после номера с отступом. Как выровнять текст по первой строке текста вместо выравнивания по отступу?

Please find the below code

//bullets 6 and 7 text to be written in word document
string value = "6.   According to the latest available equalized assessment roll in the office of the county tax assessor, the assessor's parcel number(s) for the above-mentioned legal description is/are _________, which also include(s) other property.
7.   Appurtenant _________ easement in common with others in accordance with the terms and conditions relative to the use thereof.";
//bookmark
string name = "COMEXCEPTIONS";
string[] newLineArray = { Environment.NewLine, "\n" };
 var bookMark = Document.MainDocumentPart.Document.Body.Descendants<BookmarkStart>().Where(bm => bm.Name.ToString().ToUpper() == name);
foreach (BookmarkStart bm in bookMark)
                    {
                        if (bm.Name.ToString().ToUpper() == name.ToUpper())
                        {
                            var textReplacementPending = true;
                            Run sib = bm.NextSibling<Run>();
                            if (sib == null)
                            {
                                bool isEmptyField = false; 
                                if (!IsFormFiled)
                                {
                                    isEmptyField = name.Equals(value);
                                }

                                WordToolKitExtension wd = new WordToolKitExtension();
                                wd.SetBookmarkText(bm, value, !isEmptyField);
                            }


                            while (textReplacementPending && sib != null)
                            {

                                var fieldChars = sib.Descendants<FieldChar>();
                                foreach (FieldChar fieldChar in fieldChars)
                                {

                                    if (fieldChar.FieldCharType == FieldCharValues.Separate)
                                    {
                                        if (!IsFormFiled)
                                        {
                                            RunProperties runProperties17 = new RunProperties();
                                            Color color10 = new Color() { Val = "FF0000" };
                                            runProperties17.Append(color10);
                                            sib.Append(runProperties17);
                                        }

                                        Text text12 = new Text();
                                        if (name.ToUpper() == POLICY_DAY.ToUpper() ||
                                            name.ToUpper() == POLICY_MONTH.ToUpper())
                                            text12.Text = !string.IsNullOrEmpty(value) ? value.ToUpper() : value;
                                        else
                                        {
                                            text12.Text = value;
                                        }



                                        if (!string.IsNullOrEmpty(value) && value.Split(newLineArray, StringSplitOptions.None).Count() <= 1)
                                        {
                                            sib.Append(text12);
                                            try
                                            {

                                                OpenXmlElement elem = sib.NextSibling();
                                                //if (sib.Descendants<OpenXmlElement>() != null)
                                                //    k = sib.Descendants<OpenXmlElement>().Count();
                                                while (elem != null && !(elem is BookmarkEnd))
                                                {
                                                    OpenXmlElement nextElem = elem.NextSibling();

                                                    if (nextElem.ChildElements.Count > 0)
                                                    {
                                                        elem.Remove();
                                                        elem = nextElem;
                                                    }
                                                    else
                                                        return;
                                                }
                                            }
                                            catch (Exception ex)
                                            {

                                            }
                                        }
                                        else
                                            if (!string.IsNullOrEmpty(value))
                                                ParseForOpenXML(ref sib, value);
                                        textReplacementPending = false;
                                        return;
                                    }
                                }
                                sib = sib.NextSibling<Run>();
                                if (sib == null)
                                    return;

                            }
                        }
                    }



public void ParseForOpenXML(ref Run run, string textualData)
        {
            try
            {
                string[] newLineArray = { Environment.NewLine, "\n" };
                string[] textArray = textualData.Split(newLineArray, StringSplitOptions.None);
                bool first = true;
                foreach (string line in textArray)
                {
                    if (!first)
                    {
                        run.Append(new Break());
                    }

                    first = false;

                    Text txt = new Text();
                    txt.Text = line;
                    run.Append(txt);
                }
            }
            catch (Exception ex)
            {
                throw ex);
            }
        }
...