Get and edit content controls starts to be supported in Spire.Doc 5.4.15

Spire.Doc

We are glad to announce the new hotfix version of Spire.Doc 5.4.15 today. We add new feature to enable developers to get and edit the contents in Combox, Dropdownlist and CheckBox. We also fixed bugs in this version. View the details as below:

New feature:

Add new feature to get and edit content controls (Combox, Dropdownlist,CheckBox).

static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile("..\\..\\sample.docx");
            foreach(Section section in document.Sections)
            {
                foreach(Body body in section.ChildObjects)
                {
                    ModifyBody(body);
                }
            }
            document.SaveToFile("result.docx",FileFormat.Docx);
            System.Diagnostics.Process.Start("result.docx");
        }
        static void ModifyBody(Body body)
        {
            if (body == null)
                return;
            foreach (DocumentObject docObj in body.ChildObjects)
            {
                if (docObj is StructureDocumentTag)
                {
                    SDTProperties SdtProperties = (docObj as StructureDocumentTag).SDTProperties;
                    ModifySdtProperties(SdtProperties);
                }
                else if (docObj is Table)
                {
                    ModifyTable(docObj as Table);
                }
                else if (docObj is Paragraph)
                {
                    ModifyParagraph(docObj as Paragraph);
                }
            }
        }

        static void ModifyTable(Table table)
        {
            if (table == null)
                return;
            foreach (TableRow row in table.Rows)
            {
                foreach (TableCell cell in row.Cells)
                {
                    if (cell is StructureDocumentTagCell)
                    {
                        SDTProperties SdtProperties = (cell as StructureDocumentTagCell).SDTProperties;
                        ModifySdtProperties(SdtProperties);   
                    }
                    else
                    {
                        ModifyBody(cell);
                    }
                }
            }
        }

        static void ModifyParagraph(Paragraph para)
        {
            if (para == null)
                return;

            foreach (DocumentObject docObj in para.ChildObjects)
            {
                if (docObj is StructureDocumentTagInline)
                {
                    SDTProperties SdtProperties = (docObj as StructureDocumentTagInline).SDTProperties;
                    ModifySdtProperties(SdtProperties);
                }
            }
        }
        public class StructureTags
        {
            List m_tagInlines;
            public List tagInlines
            {
                get
                {
                    if (m_tagInlines == null)
                        m_tagInlines = new List();
                    return m_tagInlines;
                }
                set
                {
                    m_tagInlines = value;
                }
            }
            List m_tags;
            public List tags
            {
                get
                {
                    if (m_tags == null)
                        m_tags = new List();
                    return m_tags;
                }
            }

            List m_sdtCell;
            public List SDTCell
            {
                get
                {
                    if (m_sdtCell == null)
                        m_sdtCell = new List();
                    return m_sdtCell;
                }
            }
        }
        static void ModifySdtProperties(SDTProperties properties)
        {
            if (properties == null)
                return;

            switch (properties.SDTType)
            {
                case SdtType.ComboBox:
                case SdtType.DropDownList:
                    {
                        SdtDropDownListBase dropDownListBase = (properties.ControlProperties as SdtDropDownListBase);
                        dropDownListBase.ListItems.SelectedValue = dropDownListBase.ListItems[1];
                        dropDownListBase.ListItems.Add(new SdtListItem("bill","apple"));
                    }
                    break;
                case SdtType.CheckBox:
                    {
                        SdtCheckBox sdtCheckBox = (properties.ControlProperties as SdtCheckBox);
                        sdtCheckBox.Checked = !sdtCheckBox.Checked;
                    }
                    break;
            }
        }

Bug Solutions:

  • Fixes the issue where it failed to convert .doc to rtf.
  • Fixes the issue where INCLUDEPICTURE path caused image not displayed when convert rtf to pdf.
  • Fixes the issue that caused the content lost when convert .docx to pdf.
  • Resolves the issue that caused the exception "the width for height of a square {X=0,Y=0,Width=0,Height=0} can't be 0 (null)" when convert .doc to pdf.
  • Addresses the issue that caused the content disorder when convert .doc to rtf.
  • Fixes the issue caused the empty merge fields in resulted document not be cleaned when mail merge.
  • Fixes the issue where the document printed incorrectly when change display screen fonts to larger than normal.
  • Fixes the issue where generated word document can't be opened when apply TextWrappingStyle.Through option to image.
  • Fixes the issue where the image wasn't merged when use path.

Welcome to experience Spire.Doc 5.4.15 with downloading here:

http://www.e-iceblue.com/Download/download-word-for-net-now.html