Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Jul 01, 2017 8:10 pm

Hello,
I want to add Dynamic text boxes by clicking a button and after it when i click another button it should use Replace function to change text in the word document with the text I write in the newly added Textbox(es). I use a Code which adds Textbox To the windows form but I'cant connect spire.doc doc.Replace() function to it See the code Below:
Code: Select all
int A=1
      private void button21_Click(object sender, EventArgs e)
        {
            AddNewTextBox();
        }
        public System.Windows.Forms.TextBox AddNewTextBox()
        {
            System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
            this.panel5.Controls.Add(txt);
            txt.Top = A * 28;
            txt.Left = 15;
            txt.Name = "text" + this.A.ToString();
            A = A + 1;
            return txt;
}

Thank you very much.

kotechkh
 
Posts: 6
Joined: Thu Jun 01, 2017 1:56 pm

Mon Jul 03, 2017 4:05 am

Dear kotechkh,

Sorry for late reply as weekend.
You could add a new button and write replace function into it. After adding the text which needs to be replaced, then click the button, it would run the replace function. Here is whole code for your kind reference.
Code: Select all
        int A=1;
        System.Windows.Forms.TextBox textBox;
        private void button1_Click(object sender, EventArgs e)
        {
            textBox = AddNewTextBox();
        }
        public System.Windows.Forms.TextBox AddNewTextBox()
        {
            System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
            this.panel1.Controls.Add(txt);
            txt.Top = A * 28;
            txt.Left = 15;
            txt.Name = "text" + this.A.ToString();
            A = A + 1;
            return txt;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Document doc = new Document("Sample.docx");
            doc.Replace("Hello",textBox.Text, false, false);
            doc.SaveToFile("result.docx", FileFormat.Docx);
        }

Hope this helps. If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jul 04, 2017 7:23 am

Dear kotechkh,

How is the issue now ?
Could you please give us some feedback at your convenience ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc