wordpress hit counter
OpenXML Developer
Goodbye and Hello

OpenXmlDeveloper.org is Shutting Down

There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.

Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.

Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.

Please see this blog post for more information about my plans moving forward.  Cheers, Eric

Structured Document Tags + Formatting?

  • rated by 0 users
  • This post has 2 Replies |
  • 1 Follower
  • Hi everyone,

    i am currently experimenting with WordprocessingML and got to a behavior i can't follow.

    Some words of explanation: Before i start writing any C# code and use the Open XML SDK, i want to understand the concept of the XML part resources inside a docx package. So this is why i edit the XML files manually, "pack" them again and try to open the docx in Word 2013 and chek whether the result is what i want.

    My goal is to understand the theory of creating a docx template with text formatting and every view related configuration and merging this with a new customXML file part which has the actual data in it. (In the process of this, i am trying to find the minimal data needed for word to open the document.)

    So, for populating the word template with data, i came across SDT's which seem to fulfill all my requirements.

    This is my document.xml (xml declaration and xmlns are omitted):

    <w:body>
                <w:sdt>
                      <w:sdtPr>
                            <w15:dataBinding w:prefixMappings="" w:xpath="/BankStatement[1]/TransactionRecords[1]/TransactionRecord" w:storeItemID="{FA52C880-B464-4375-9F86-E5D051525B7D}"/>
                            <w15:repeatingSection/>
                      </w:sdtPr>
                      <w:sdtContent>
                            <w:sdt>
                                  <w:sdtPr>
                                        <w15:repeatingSectionItem/>
                                  </w:sdtPr>
                                  <w:sdtContent>
                                        <w:sdt>
                                              <w:sdtPr>
                                                    <w:dataBinding w:prefixMappings="" w:xpath="/BankStatement[1]/TransactionRecords[1]/TransactionRecord[1]/transactionDate[1]" w:storeItemID="{FA52C880-B464-4375-9F86-E5D051525B7D}"/>
                                                    <w:text/>
                                              </w:sdtPr>
                                              <w:sdtEndPr>
                                                    <w:rPr>
                                                          <w:b/>
                                                    </w:rPr>
                                              </w:sdtEndPr>
                                              <w:sdtContent>
                                                    <w:p>
                                                          <w:r>
                                                                <w:rPr>
                                                                      <w:b/>
                                                                </w:rPr>
                                                                <w:t></w:t>
                                                          </w:r>
                                                    </w:p>
                                              </w:sdtContent>
                                        </w:sdt>
                                        <w:sdt>
                                              <w:sdtPr>
                                                    <w:dataBinding w:prefixMappings="" w:xpath="/BankStatement[1]/TransactionRecords[1]/TransactionRecord[1]/valueDate[1]" w:storeItemID="{FA52C880-B464-4375-9F86-E5D051525B7D}"/>
                                                    <w:text/>
                                              </w:sdtPr>
                                              <w:sdtEndPr>
                                                    <w:rPr>
                                                          <w:b/>
                                                    </w:rPr>
                                              </w:sdtEndPr>
                                              <w:sdtContent>
                                                    <w:p>
                                                          <w:r>
                                                                <w:rPr>
                                                                      <w:b/>
                                                                </w:rPr>
                                                                <w:t></w:t>
                                                          </w:r>
                                                    </w:p>
                                              </w:sdtContent>
                                        </w:sdt>
                                        <w:sdt>
                                              <w:sdtPr>
                                                    <w:dataBinding w:prefixMappings="" w:xpath="/BankStatement[1]/TransactionRecords[1]/TransactionRecord[1]/value[1]" w:storeItemID="{FA52C880-B464-4375-9F86-E5D051525B7D}"/>
                                                    <w:text/>
                                              </w:sdtPr>
                                              <w:sdtEndPr>
                                                    <w:rPr>
                                                          <w:b/>
                                                    </w:rPr>
                                              </w:sdtEndPr>
                                              <w:sdtContent>
                                                    <w:p>
                                                          <w:r>
                                                                <w:rPr>
                                                                      <w:b/>
                                                                </w:rPr>
                                                                <w:t></w:t>
                                                          </w:r>
                                                    </w:p>
                                              </w:sdtContent>
                                        </w:sdt>
                                        <w:sdt>
                                              <w:sdtPr>
                                                    <w:dataBinding w:prefixMappings="" w:xpath="/BankStatement[1]/TransactionRecords[1]/TransactionRecord[1]/type[1]" w:storeItemID="{FA52C880-B464-4375-9F86-E5D051525B7D}"/>
                                                    <w:text/>
                                              </w:sdtPr>
                                              <w:sdtEndPr>
                                                    <w:rPr>
                                                          <w:b/>
                                                    </w:rPr>
                                              </w:sdtEndPr>
                                              <w:sdtContent>
                                                    <w:p>
                                                          <w:r>
                                                                <w:rPr>
                                                                      <w:b/>
                                                                </w:rPr>
                                                                <w:t>asdasdasd</w:t>
                                                          </w:r>
                                                    </w:p>
                                              </w:sdtContent>
                                        </w:sdt>
                                  </w:sdtContent>
                            </w:sdt>
                      </w:sdtContent>
                </w:sdt>
                <w:sectPr w:rsidR="00E247BB" w:rsidRPr="00E247BB">
                      <w:pgSz w:w="11906" w:h="16838"/>
                      <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
                      <w:cols w:space="708"/>
                      <w:docGrid w:linePitch="360"/>
                </w:sectPr>
          </w:body>

    While this already works for populating the template, i cant define any formatting for the SDT's. So when i open this document, all my data is visible but every

    <w:sdtEndPr>
       <w:rPr>
          <w:b/>
       </w:rPr>
    </w:sdtEndPr>

    Seems to be ignored because none of my data is rendered bold...

    Any ideas? Thanks in advance!

  • no one ever did this by hand and wondered about the formatting?

    Sorry, i am new to WML and if you need more information regarding my xml parts or structuring, please let me know.

    i would appreciate every hint...

  • Nvm, i got a solution for my problem.

Page 1 of 1 (3 items)