简体   繁体   中英

OpenXml table control data binding

my task is to automate process of document generation from docx template and xml. i found "how to" example on http://ericwhite.com/blog/2011/03/29/release-of-v2-of-doc-gen-system-xpath-in-content-controls/

But i run into problem and don't know how to deal with complex tables... For example, my table-part xml looks like:

<TBL>
 <ROW>
    <CLMN_1>0</CLMN_1>      
    <CLMN_2>Date</CLMN_2>
    <CLMN_3>Customer name</CLMN_3>
    <CLMN_4>Order No</CLMN_4>
    <CLMN_5>Account</CLMN_5>
 </ROW>
 <ROW>
    <CLMN_1>0</CLMN_1>
    <CLMN_2>Invoice date</CLMN_2>
    <CLMN_3>Customer Account/IBAN</CLMN_3>
    <CLMN_4>Explanation</CLMN_4>
    <CLMN_5>Calling number</CLMN_5>
    <CLMN_6>Cash out</CLMN_6>
    <CLMN_7>Cash in</CLMN_7>
 </ROW>
 <ROW>
    <CLMN_1>1</CLMN_1>
    <CLMN_2>Current amount</CLMN_2>
    <CLMN_3>366,47</CLMN_3>
 </ROW>
 <ROW>
    <CLMN_1>2</CLMN_1>
    <CLMN_2>05.07.2014.</CLMN_2>
    <CLMN_3 />
    <CLMN_4>2 -   Barclays ATM c7241152 Barcelona , Barcelona Street</CLMN_4>
    <CLMN_5 />
    <CLMN_6 />
    <CLMN_7 />
 </ROW>
</TBL>

and from that xml i need to create table(s) based on: first tag (clmn_1) "describes" how row should look like and what that row is (header/footer/body). In my example, if value of clmn_1 == 0 -> that row is header every other clmn_X in indicates data position in that row (for example clmn_7 data should be in 6th column etc

Can i build something like this based on eric white's example?

Link for picture and detailed explanation http://tinypic.com/r/an1w7q/8

Thx for help and ideas how to deal with this monster :)

The approach I'm suggesting is a little different to Eric's, but you can handle this using OpenDoPE repeats, in C#, using https://www.nuget.org/packages/docx4j.NET/

You'll need to create a docx with a single table row, and 7 columns, and then bind cells 1 to 7 to the corresponding CLMN_ element

Then wrap the table row in a repeating content control.

To set this up, you can use http://www.opendope.org/downloads/authoring-friendly/setup.exe

Go to the authoring tab, add your sample XML file, then drag/drop elements from the task pane onto the document surface.

Then, at run time, to inject your XML, use the C# equivalent of ContentControlsMergeXML.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM