1, first explain, what is called Dynamic Data, Dynamic Data refers to the format of a piece of data fixed, but the number of data is not fixed.
2, the application environment, in a table if, now the table has three rows n columns, if you need to add the same size row or n rows after the first row of the table, how should you do?
3, according to the above application environment, it is not difficult to find, to complete the work of 5 processes, 1, find location. 2. Get the template line. 3. Add the template line to the next line in the current row. 4. Write the value to the added line. There may be a loop procedure 5, delete the template line.
4, words not much said, on the code.
Note: To use this fragment, first add a reference to the Docx component.
Docx Project: http://docx.codeplex.com/releases/view/80870
Controls the number of rows to insert for (int i = 0; i < 5; i++) {/ /here the test succeeds//Gets the object to the template row (typically a blank line, only the shelf has no data) row InsertRow = d Ocx. Tables[0]. ROWS[26]; Will get to this one template row, added to the next row of the current row (the next node) //I am here to insert into the 27th row and later, my template row is the 27th row, I is the role of the control is the row of the operation of the docx. Tables[0]. Rows[26+i]. Xml.addafterself (insertrow.xml); Control to insert those columns for (int j = 2; J < 9; j + +) { //Set the value to insert string value = (i + j). ToString (); Adds a value to the cell docx. Tables[0]. rows[26 + i + 1]. CELLS[J]. Paragraphs[0]. Append (value); } Paragraph.Xml.ElementsBeforeSelf (); } Delete the template line, or there will be a blank line docx. Tables[0]. Removerow (26);
The
uses the Docx open source component for Dynamic Data filling.