Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a document
            Document document = new Document();

            //Add a new section.
            Section section = document.AddSection();

            //Add a paragraph
            Paragraph paragraph = section.AddParagraph();

            //Append textRange for the paragraph
            TextRange txtRange = paragraph.AppendText("The following example shows how to add RichText content control in a Word document. \n");

            //Append textRange
            txtRange = paragraph.AppendText("Add RichText Content Control:  ");

            //Set the font format
            txtRange.CharacterFormat.Italic = true;

            //Create StructureDocumentTagInline for document
            StructureDocumentTagInline sdt = new StructureDocumentTagInline(document);

            //Add sdt in paragraph
            paragraph.ChildObjects.Add(sdt);

            //Specify the type
            sdt.SDTProperties.SDTType = SdtType.RichText;

            //Set displaying text
            SdtText text = new SdtText(true);

            text.IsMultiline = true;
            sdt.SDTProperties.ControlProperties = text;

            //Crate a TextRange
            TextRange rt = new TextRange(document);

            rt.Text = "Welcome to use ";
            rt.CharacterFormat.TextColor = Color.Green;
            sdt.SDTContent.ChildObjects.Add(rt);

            rt      = new TextRange(document);
            rt.Text = "Spire.Doc";
            rt.CharacterFormat.TextColor = Color.OrangeRed;
            sdt.SDTContent.ChildObjects.Add(rt);

            //Save the document.
            document.SaveToFile("Output.docx", FileFormat.Docx);

            //Launch the Word file.
            WordDocViewer("Output.docx");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a document
            Document document = new Document();

            //Add a new section.
            Section section = document.AddSection();

            //Add a paragraph
            Paragraph paragraph = section.AddParagraph();

            //Append textRange for the paragraph
            TextRange txtRange = paragraph.AppendText("The following example shows how to add CheckBox content control in a Word document. \n");

            //Append textRange
            txtRange = paragraph.AppendText("Add CheckBox Content Control:  ");

            //Set the font format
            txtRange.CharacterFormat.Italic = true;

            //Create StructureDocumentTagInline for document
            StructureDocumentTagInline sdt = new StructureDocumentTagInline(document);

            //Add sdt in paragraph
            paragraph.ChildObjects.Add(sdt);

            //Specify the type
            sdt.SDTProperties.SDTType = SdtType.CheckBox;

            //Set properties for control
            SdtCheckBox scb = new SdtCheckBox();

            sdt.SDTProperties.ControlProperties = scb;

            //Add textRange format
            TextRange tr = new TextRange(document);

            tr.CharacterFormat.FontName = "MS Gothic";
            tr.CharacterFormat.FontSize = 12;

            //Add textRange to StructureDocumentTagInline
            sdt.ChildObjects.Add(tr);

            //Set checkBox as checked
            scb.Checked = true;

            //Save the document.
            document.SaveToFile("Output.docx", FileFormat.Docx);

            //Launch the Word file.
            WordDocViewer("Output.docx");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load document from disk
            Document doc = new Document();
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\RemoveContentControls.docx");

            //Loop through sections
            for (int s = 0; s < doc.Sections.Count; s++)
            {
                Section section = doc.Sections[s];
                for (int i = 0; i < section.Body.ChildObjects.Count; i++)
                {
                    //Loop through contents in paragraph
                    if (section.Body.ChildObjects[i] is Paragraph)
                    {
                        Paragraph para = section.Body.ChildObjects[i] as Paragraph;
                        for (int j = 0; j < para.ChildObjects.Count; j++)
                        {
                            //Find the StructureDocumentTagInline
                            if (para.ChildObjects[j] is StructureDocumentTagInline)
                            {
                                StructureDocumentTagInline sdt = para.ChildObjects[j] as StructureDocumentTagInline;
                                //Remove the content control from paragraph
                                para.ChildObjects.Remove(sdt);
                                j--;
                            }
                        }
                    }
                    if (section.Body.ChildObjects[i] is StructureDocumentTag)
                    {
                        StructureDocumentTag sdt = section.Body.ChildObjects[i] as StructureDocumentTag;
                        section.Body.ChildObjects.Remove(sdt);
                        i--;
                    }
                }
            }

            //Save the Word document
            string output = "RemoveContentControls_out.docx";
            doc.SaveToFile(output, FileFormat.Docx2013);

            //Launch the file
            WordDocViewer(output);
        }
Example #4
0
 public override VisitorAction vmethod_44(StructureDocumentTagInline A_0)
 {
     A_0.UpdateDataBinding();
     return(VisitorAction.Continue);
 }
        private void button1_Click(object sender, EventArgs e)
        {
            //Creat a new word document.
            Document  document  = new Document();
            Section   section   = document.AddSection();
            Paragraph paragraph = section.AddParagraph();
            TextRange txtRange  = paragraph.AppendText("The following example shows how to add content controls in a Word document.");

            paragraph = section.AddParagraph();

            //Add Combo Box Content Control.
            paragraph = section.AddParagraph();
            txtRange  = paragraph.AppendText("Add Combo Box Content Control:  ");
            txtRange.CharacterFormat.Italic = true;
            StructureDocumentTagInline sd = new StructureDocumentTagInline(document);

            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.ComboBox;
            SdtComboBox cb = new SdtComboBox();

            cb.ListItems.Add(new SdtListItem("Spire.Doc"));
            cb.ListItems.Add(new SdtListItem("Spire.XLS"));
            cb.ListItems.Add(new SdtListItem("Spire.PDF"));
            sd.SDTProperties.ControlProperties = cb;
            TextRange rt = new TextRange(document);

            rt.Text = cb.ListItems[0].DisplayText;
            sd.SDTContent.ChildObjects.Add(rt);

            section.AddParagraph();

            //Add Text Content Control.
            paragraph = section.AddParagraph();
            txtRange  = paragraph.AppendText("Add Text Content Control:  ");
            txtRange.CharacterFormat.Italic = true;
            sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.Text;
            SdtText text = new SdtText(true);

            text.IsMultiline = true;
            sd.SDTProperties.ControlProperties = text;
            rt      = new TextRange(document);
            rt.Text = "Text";
            sd.SDTContent.ChildObjects.Add(rt);

            section.AddParagraph();

            //Add Picture Content Control.
            paragraph = section.AddParagraph();
            txtRange  = paragraph.AppendText("Add Picture Content Control:  ");
            txtRange.CharacterFormat.Italic = true;
            sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.Picture;
            DocPicture pic = new DocPicture(document);

            pic.Width  = 10;
            pic.Height = 10;
            pic.LoadImage(Image.FromFile(@"..\..\..\..\..\..\Data\logo.png"));
            sd.SDTContent.ChildObjects.Add(pic);

            section.AddParagraph();

            //Add Date Picker Content Control.
            paragraph = section.AddParagraph();
            txtRange  = paragraph.AppendText("Add Date Picker Content Control:  ");
            txtRange.CharacterFormat.Italic = true;
            sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.DatePicker;
            SdtDate date = new SdtDate();

            date.CalendarType = CalendarType.Default;
            date.DateFormat   = "yyyy.MM.dd";
            date.FullDate     = DateTime.Now;
            sd.SDTProperties.ControlProperties = date;
            rt      = new TextRange(document);
            rt.Text = "1990.02.08";
            sd.SDTContent.ChildObjects.Add(rt);

            section.AddParagraph();

            //Add Drop-Down List Content Control.
            paragraph = section.AddParagraph();
            txtRange  = paragraph.AppendText("Add Drop-Down List Content Control:  ");
            txtRange.CharacterFormat.Italic = true;
            sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.DropDownList;
            SdtDropDownList sddl = new SdtDropDownList();

            sddl.ListItems.Add(new SdtListItem("Harry"));
            sddl.ListItems.Add(new SdtListItem("Jerry"));
            sd.SDTProperties.ControlProperties = sddl;
            rt      = new TextRange(document);
            rt.Text = sddl.ListItems[0].DisplayText;
            sd.SDTContent.ChildObjects.Add(rt);

            //Save the document.
            string resultfile = "Output.docx";

            document.SaveToFile(resultfile, FileFormat.Docx);

            //Launch the Word file.
            FileViewer(resultfile);
        }
Example #6
0
 public virtual VisitorAction vmethod_45(StructureDocumentTagInline A_0)
 {
     return(VisitorAction.Continue);
 }