Use DocX open-source components to fill in dynamic data ., Docx Dynamic Data

Source: Internet
Author: User

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 );

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.