Use DocX open-source components to fill in dynamic data ., Docx Dynamic Data
1. First, Let's explain what dynamic data means. Dynamic Data means that the format of a piece of data is fixed, but the number of data entries is not fixed.
2. Application Environment: in a table, if the table now has three rows and n columns, if you need to add one or n rows of the same type after the first row of the table, what should I do?
3. According to the above application environment, it is not difficult to find the five processes to complete the work. 1. Locate the location. 2. Obtain the template row. 3. Add the template row to the next row of the current row. 4. Write the value to the added row. There may be a loop process. 5. Delete the template row.
4. Let's talk about the code.
Note: To use this clip, add a reference to the DocX component first.
DocX item: http://docx.codeplex.com/releases/view/80870
// Control the number of rows to be inserted for (int I = 0; I <5; I ++) {// The test is successful here. // the object that obtains the template Row (usually an empty Row with no data on the shelf) Row insertRow = docx. tables [0]. rows [26]; // Add the obtained template row to the next row of the current row (next node) // insert it to row 27th and later, my template row is 27th rows, and I is used to control the docx. tables [0]. rows [26 + I]. xml. addAfterSelf (insertRow. xml); // control the columns to insert for (int j = 2; j <9; j ++) {// set the string value to be inserted = (I + j ). toString (); // Add the value to the docx cell. tables [0]. rows [26 + I + 1]. cells [j]. paragraphs [0]. append (value);} // Paragraph. xml. elementsBeforeSelf ();} // Delete the template row. Otherwise, there will be an empty line docx. tables [0]. removeRow (26 );