0

I'm working with the Microsoft.Office.Interop.Word (v14.0).

I have a word document. In that word document I created a table with 3 Columns and added 1 row to the table.

Each of the 3 cells in the first row are containing a field. When the user press print button on my Window/Form I take the informations (positions, with 3 attributes in my UI context) and use Microsoft word template, my word document that has this row with the 3 cells to be filled with these info coming from WPF Window / (same as Windows Forms).

Actually, the problem is, I don't know how I can copy an existing tablerow. The quantity of positions (describing one Row), can be different and I search a way, how to copy an existing row, with these 3 fields in it and add it just at the bottom. Or an other way would be, to create a row, and these fields, foreach cell, dynamically.. Anyway

How can I do that?

Well, adding rows doesn't seem to be a problem (Code from MSDN):

object beforeRow = this.Tables[1].Rows[1];
this.Tables[1].Rows.Add(ref beforeRow);
4

2 に答える 2

1

Edit: something like this might work: I'm not sure what should be passed as the Range parameter to Fields.Add though.

object beforeRow = this.Tables[1].Rows[1];
Row newRow = this.Tables[1].Rows.Add(ref beforeRow);

Field fld = beforeRow.Cells[0].Range.Fields[0];
Range range = fld.Range; // newRow.Cells[0].Range ?
newRow.Cells[0].Range.Fields.Add(ref range, ref fld.Type, ref missing, ref missing);
于 2012-07-11T12:45:24.493 に答える
0

Use Range.Copy() Method.

Row beforeRow = this.Tables[1].Rows[1];
beforeRow.Range.Copy();
beforeRow.Range.Paste();
于 2019-10-11T23:55:17.673 に答える