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.

Tue Oct 24, 2017 11:16 am

Hi
I need to open a document, replace some text on it and write down a table. My problem is the table is in a new page and not after the text of the document. Please look at my code:
Code: Select all
 Spire.Doc.Document doc = new Spire.Doc.Document();
        doc.LoadFromFile(@"C:\**********\choca-vendalivros.docx");
        doc.Replace("Livro", DropDownList1.SelectedItem.Text, false, true);
        doc.Replace("datainicial", from.Text, false, true);
        doc.Replace("datafinal", to.Text, false, true);
        doc.Replace("isbn", "12121", false, true); 
        Section s = doc.AddSection();
        Paragraph Paras = s.AddParagraph();
        Paras.AppendText("Listagem de Vendas do Livro: "+DropDownList1.SelectedItem.Text);                 
        Spire.Doc.Table table = s.AddTable(true);

The problem, I think, it's because I create a new Section. Any help on this?
Thank you

mariolopes
 
Posts: 9
Joined: Thu Oct 19, 2017 11:06 am

Wed Oct 25, 2017 1:55 am

Hello mariolopes,

Thanks for your inquiry.
Yes, you are absolutely right! When creating a section, a section break(next page) will be automatically added, thus the table appears in the new page. If you want to insert a table just after the text in the same page, please first get the section. Just refer to the code below.
Code: Select all
 Spire.Doc.Document doc = new Spire.Doc.Document();
        doc.LoadFromFile(@"C:\**********\choca-vendalivros.docx");
        doc.Replace("Livro", DropDownList1.SelectedItem.Text, false, true);
        doc.Replace("datainicial", from.Text, false, true);
        doc.Replace("datafinal", to.Text, false, true);
        doc.Replace("isbn", "12121", false, true);
        Section s= doc.Sections[0];
        Paragraph Paras = s.AddParagraph();
        Paras.AppendText("Listagem de Vendas do Livro: "+DropDownList1.SelectedItem.Text);                 
        Spire.Doc.Table table = s.AddTable(true);


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Oct 25, 2017 2:11 pm

Perfect!
A great product and a fantastic support.
Thank you
mario

mariolopes
 
Posts: 9
Joined: Thu Oct 19, 2017 11:06 am

Thu Oct 26, 2017 1:38 am

Hi mario,

Thanks for your valuable feedback.
Please feel free to contcat us if you need further assistance.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Doc