none
Issue with XML / database link / altChunk RRS feed

  • Question

  • Hello

    During this post I refer to some example word docs - these are available at:

    http://cid-870c2aea9fff46ce.office.live.com/self.aspx/MSP%20site/altChunk%20Examples.zip

    We have devised our own code that uses OpenXML to insert data from a database into Word documents when the end user clicks a button in our main application.  The Word documents often require updating by users when they make a change to their data in the main application, and as such we use a rich text content control to identify the position where the data should be inserted (this makes it easy to remove any previously inserted values and replace them when the user requires an update).  This content control is within another rich text content control that holds information about which field should be inserted.  Attached is a file named “altChunk Example.docx” which shows a very simple example of a document (inserts a single RTF database value into a child rich text content control) that has not yet been populated by our custom code.

     

    We have no issues inserting plain text values from our database, but we are experiencing some difficulties when attempting to insert RTF data with line breaks inside the child rich text content control.  Our “InsertRichText” method shown in the “altChunk Example.docx” document simply feeds the RTF value from the database via a stream into a new <w:altChunk> object, which in turn is placed into the child content control.  When the document.xml file is examined, we can see that using altChunk to import our data into the child content control has been successful:

    <
    w
    :
    sdt
    >
    
    < w : sdtPr >
    < w : placeholder >
    < w : docPart w:val = " 4801021AD6CE45DB8C16C4547CF4AD60 " />
    </ w : placeholder >
    </ w : sdtPr >
    < w : sdtContent >
    < w : altChunk r:id = " a422e4111 " />
    </ w : sdtContent >
    </ w : sdt >


    However, when the document is opened in Word, we can see the conversion of the <w:altChunk> object by Word has moved any text after the first line break outside of the child rich text content control, overflowing into the parent rich text content control.

    Please see the attached document “altChunk Example_Output_Before_Save.docx” that shows this in action.

    We have tried wrapping the <w:altChunk> object inside a <w:r> tag, but this has not helped. 

    When the user makes changes anywhere in the document and saves it, this of course causes the altChunk to be properly converted to Word format, and still the first line is inside the content control whilst any other lines are pushed outside (please see attached document “altChunk Example_Output_After_Save.docx”).  We have tried this in Word 2007 and Word 2010.

     

    To the end user everything looks correct, but unfortunately our application cannot read in any changes they make to the data that are outside of the content control.  Rich text content controls are the only safe way for us to reference the field values and feed them (along with any user changes made with Word) back into the database.

    Could you please let us know if this is a bug and/or if there is a workaround for this issue.

    Thank you.

    Karl

    • Moved by Bruce Song Monday, February 28, 2011 7:21 AM (From:Word for Developers)
    Friday, February 25, 2011 9:47 AM

All replies

  • Hi Karl,

    Thanks for posting. I am trying to involve someone who is familiar with this issue. So, there might be some delay. Appreciate your patience. Thank you for your understanding and support.

    Best Regards,

     


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 28, 2011 7:42 AM
  • Hi Karl,

    The list of tags in your post includes only one <w:sdtContent></w:sdtContent>pair so isn't enough to reconstruct your actual document. The .docx file you attached to the post isn't shown or findable. You might be able to get some help by looking through all of the content available about the use of AltChunk through a query on the argument 'AltChunk' in the Bing search engine. It provides a host of hits including a link to the AltChunk class.

    Could you paste the contents of the Alchunk.dat file, the _rels file and the document.xml file of your document into a reply to this post, using a very simple example similar to the ones on the AltChunk.zip that you pointed to in your post at
    http://cid-870c2aea9fff46ce.office.live.com/self.aspx/MSP%20site/altChunk%20Examples.zip

    As an alternative, do you have a way to create a very similar collection of demonstration documents and post them to a public share such as the SkyDrive component of Windows Live.

     

    Monday, February 28, 2011 10:31 PM
    Moderator
  • Hello

    Apologies for the delay in responding to this.

    I thin I may have given you a misleading link there.

    The file you request is on Windows Live at:

    http://public.bay.livefilestore.com/y1p2wS0XfIwMZbUsxb1Q9CQQdJyHlC9aiEruC4TTnqQbAc2OmGreLuVdn6vNpUYBoBMhC0jjpw3Y9yMY4dzEqAHdw/Before%20-%20AltChunk%20Imported.zip?download&psid=1

    - if you use that link it should download the file immediately. 

    For completeness, the code is:

    From the .rels file:

     <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
    - <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
     <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml" /> 
     <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml" /> 
     <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" /> 
     </Relationships>

    From the afchunk.dat file:

    {\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl
    {\f0\fnil\fcharset0\fprq2 Arial;}
    {\f1\fswiss\fcharset0\fprq2 Verdana;}
    {\f2\froman\fcharset2\fprq2 Symbol;}}
    {\colortbl;\red0\green0\blue0;\red255\green255\blue255;}
    {\stylesheet{\s0\itap0\nowidctlpar\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}}
    {\*\generator TX_RTF32 15.1.531.502;}
    \deftab1134\paperw12240\paperh15840\margl1440\margt1440\margr1440\margb1440\widowctrl\formshade\sectd
    \headery720\footery720\pgwsxn12240\pghsxn15840\marglsxn1440\margtsxn1440\margrsxn1440\margbsxn1440\pard\itap0\nowidctlpar\plain\f1\fs20 This is the Description field, saved as an RTF value in the database.\par This is the second line of the field.\par This is the third line of the field.\par\pard\itap0\nowidctlpar\par }

    And finally the XML file:

     <?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
    - <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
    - <w:body>
    - <w:p w:rsidR="009D3816" w:rsidRDefault="009D3816" w:rsidP="009D3816">
    - <w:r>
     <w:t>Inserted value:</w:t> 
     </w:r>
     </w:p>
    - <w:sdt>
    - <w:sdtPr>
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
    - <w:placeholder>
     <w:docPart w:val="DefaultPlaceholder_22675703" /> 
     </w:placeholder>
     </w:sdtPr>
    - <w:sdtEndPr>
    - <w:rPr>
     <w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi" /> 
     <w:sz w:val="22" /> 
     <w:szCs w:val="22" /> 
     <w:lang w:val="en-GB" w:eastAsia="en-US" /> 
     </w:rPr>
     </w:sdtEndPr>
    - <w:sdtContent>
    - <w:p w:rsidR="009D3816" w:rsidRDefault="009D3816" w:rsidP="009D3816">
    - <w:pPr>
     <w:pStyle w:val="StandardVorNach6pt" /> 
     </w:pPr>
    - <w:r w:rsidRPr="004F0279">
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t>InsertRichT</w:t> 
     </w:r>
    - <w:r>
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t>ext(Get(Audit</w:t> 
     </w:r>
    - <w:r w:rsidRPr="004F0279">
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t xml:space="preserve">,</w:t> 
     </w:r>
    - <w:r>
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t>aud_Description</w:t> 
     </w:r>
    - <w:r w:rsidRPr="004F0279">
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t>_RTF),1)</w:t> 
     </w:r>
    - <w:sdt>
    - <w:sdtPr>
    - <w:placeholder>
     <w:docPart w:val="4801021AD6CE45DB8C16C4547CF4AD60" /> 
     </w:placeholder>
     </w:sdtPr>
    - <w:sdtContent>
     <w:altChunk r:id="a422e4111" /> 
     </w:sdtContent>
     </w:sdt>
     </w:p>
    - <w:p w:rsidR="009D3816" w:rsidRDefault="009D3816" w:rsidP="009D3816">
    - <w:r w:rsidRPr="00E66D5E">
    - <w:rPr>
     <w:vanish /> 
     </w:rPr>
     <w:t><EC></w:t> 
     </w:r>
     </w:p>
     </w:sdtContent>
     </w:sdt>
    - <w:sectPr w:rsidR="009D3816" w:rsidSect="008515D0">
     <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>
     </w:document>

    In case you want to see the 'After' state, I've uploaded the files to http://public.bay.livefilestore.com/y1p2wS0XfIwMZaQGtGOxw4EBnxuocOFRc5VNfo7p76XT4Is2hIZFxmTo1PEk0-zzGKiJw4Gm5L4PcAnWSICGuaANw/After%20-%20AltChunk%20Merged%20By%20Save.zip?download&psid=1

    Thanks.

     

    Tuesday, March 8, 2011 10:21 AM
  • Hello Karlin,

    Thank you for the thoroughness involved in composing your reply.

    Because of its complexity your question falls into the paid support category which requires a more in-depth level of support.  If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. Please visit the below link to see the various paid support options that are available to better meet your needs.

     

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Tuesday, March 8, 2011 2:41 PM
    Moderator