How to insert text into existing tables

Technical support for Spire.Doc

Moderator: iceblue support

How to insert text into existing tables

Postby pbernhardt » Tue Mar 08, 2011 2:14 pm

Hello,

is it possible to open an existing document that contains tables and edit the content of the tables? (for example replace text and add rows)

Thank you for your help!
pbernhardt
 
Posts: 11
Joined: Thu Mar 03, 2011 1:55 pm

Re: How to insert text into existing tables

Postby harry.support » Thu Mar 10, 2011 2:19 am

Hi,
Thanks for your inquiry.
You could edit an existing table via Spire.Doc, for example:
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Interface;

namespace EditTable
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document(@"..\..\Table.doc");
            Section section = doc.Sections[0];
            ITable table = section.Tables[0];

#region replace text
            TableCell cell1 = table.Rows[1].Cells[1];
            Paragraph p1 = cell1.Paragraphs[0];
            p1.Text = "abc";

            TableCell cell2 = table.Rows[1].Cells[2];
            Paragraph p2 = cell2.Paragraphs[0];
            p2.Items.Clear();
            p2.AppendText("def");

            TableCell cell3 = table.Rows[1].Cells[3];
            Paragraph p3 = cell3.Paragraphs[0];
            (p3.Items[0] as TextRange).Text = "hij";
#endregion

#region add row
            TableRow newRow = table.AddRow(true, true);
            foreach (TableCell cell in newRow.Cells)
            {
                cell.AddParagraph().AppendText("new row");
            }
#endregion

            doc.SaveToFile("Table2.doc");

            System.Diagnostics.Process.Start("Table2.doc");
        }
    }
}
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: How to insert text into existing tables

Postby pbernhardt » Tue Mar 15, 2011 8:35 am

Thank you, this example was very helpful!

However, I have another question. Can you change the part where you add a row to the table so that it adds the row in the middle of the table and not at the end?
pbernhardt
 
Posts: 11
Joined: Thu Mar 03, 2011 1:55 pm

Re: How to insert text into existing tables

Postby harry.support » Wed Mar 16, 2011 1:23 am

Hi,

You could insert a new row to any index, for example:
Code: Select all
            TableRow newRow = table.AddRow(true, true);
            table.Rows.Insert(4, newRow);
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: How to insert text into existing tables

Postby pbernhardt » Thu Oct 27, 2011 8:55 am

Hi,
the insertion of text into existing tables works very well. The created document uses the border style of the tables in the template.

Now I changed our program to merge two documents which contain tables with inserted text and added cells. The problem is, that in the output document the borders of the newly created cells aren't visible.
In the document that I'm merging into the tables are fine. The problem is with the document that is being merged.

How can I change the borders to a standard style while inserting the text in the tables? (width: 0.5 pt, color: automatic/black, all borders are shown)
I have tried these commands but they didn't change anything:

- table.TableFormat.Borders.LineWidth = 0.5F;
- table.TableFormat.Borders.BorderType = Spire.Doc.Documents.BorderStyle.Single;
- table.TableFormat.Borders.Color = System.Drawing.Color.Black;
- dataRow.RowFormat.Borders.LineWidth = 0.5F;
- dataRow.Cells[c].CellFormat.Borders.LineWidth = 0.5F;
- p.Format.Borders.LineWidth = 0.5F;

Or is there a command to use the format of the input document for the output documents?
Or is there another way to solve the problem?

Thank you in advance for your help!
pbernhardt
 
Posts: 11
Joined: Thu Mar 03, 2011 1:55 pm

Re: How to insert text into existing tables

Postby Tina.Lin » Fri Oct 28, 2011 4:05 am

Hello pbernhardt,

Sorry for late reply and thank you for your inquiry.

In fact, merge two documents which means clone one section into another. For example, there is a table in each document. After merging there are two sections, and in each sections have a table. So If you want to set up two tables into a consistent format, you need to set up each of them by using Spire.Doc. I attached a demo. You can download it and have a try.

If you still have any other questions, Please don't hesitate to contact us for any thing at any time.
Have a nice day.
You do not have the required permissions to view the files attached to this post.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar
Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Re: How to insert text into existing tables

Postby pbernhardt » Wed Feb 01, 2012 1:30 pm

Hi,
the demo that was attached above works with normal tables just fine. However I have some tables that have some combined cells without visible borders. After the merging and editing of the borders these cells look really weird. I attached a screenshot of how it is supposed to look like and how it looks like after the merge. The different coloring in the screenshots isn't the problem, it's the borders. I also tried to make the borders invisible again after the merge but this didn't change the result.

Do you have any tips on how to work with these kinds of tables?

Thank you in advance!
You do not have the required permissions to view the files attached to this post.
pbernhardt
 
Posts: 11
Joined: Thu Mar 03, 2011 1:55 pm

Re: How to insert text into existing tables

Postby Suvi.Wu » Fri Feb 03, 2012 5:23 am

Hello pbernhardt,

Thank you for your inquiry and your patience with our support team.

We have tested the issue you said with the latest hotfix[Spire.Doc v4.1.20],it works fine. Could you please have a kind try with Spire.Doc v4.1.20,you can download it at http://www.e-iceblue.com/Download/download-word-for-net-now/spire-doc-hv4120.html. We also attached a demo,please have a look.

The attachment including
Table1.docx
Table2.docx
FormatSample.docx
and a project, the table in Table1.docx have some combined cells without visible borders.The FormatSample.docx is the merged document,after the merging and editing of the borders these cells look normally,please have a check.

If you still have this problem,could you please send us your original document and code to help us better solve this issue?

Thanks in advance.
Have a nice day.

Suvi
e-iceblue support
You do not have the required permissions to view the files attached to this post.
User avatar
Suvi.Wu
 
Posts: 156
Joined: Thu Oct 20, 2011 2:53 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests