ContentControl comment supprimer les champs sans données qui affichent "Cliquez ici pour taper du texte" RRS feed

  • Question

  • Bonjour,


     J'utilise OpenXml SDK pour générer des documents à partir d'un template word contenant des placeholder et en remplaçant le CustomXml par un xml contenant les données spécifique pour chacun de mes documents.

     Les placeHolder sont bien définis dans le template et le binding est correctement effectué.

     Le problème vient sur les valeurs XML vides. Les placeHolders sont alors remplis par Word avec la valeur "<!-- [if gte mso 10]> <mce:style> Cliquez ici pour taper du texte." qui est affichée et imprimée.

    Comment faire en sorte que les champs vides soient supprimés ou qu'aucune valeur ne soit affichée.

    En sachant que la solution consistant à mettre un espace au lieu d'une valeur vide décalerait le texte.

    Wednesday, May 19, 2010 5:02 PM

All replies

  • Hi neothoms,

    Thanks for your question.

    Firstly since your problem description is in French, I'm not sure if I have exactly understood your requirement. If there is anything I misunderstood, please clarity it to help better solve the problem.

    According to your description, I'm not clear that you need to just delete the "Click here to enter text" text or you need to remove the whole content control which has no data imported from the XML. If it is the former case, you could remove the Paragraph elements by calling SdtBlock.RemoveChild<Paragraph>(). If it is the latter case, you should find all the empty content controls first and call Body.RemoveChild<SdtBlock>() then.

    Hope this helps. If you have any question, please let me know.



    Thursday, May 20, 2010 1:52 AM
  • I thank you for your response.

     I already tried to remove Content controls but when I searched every StdElement there are some blocks that are not retrieved.

     I had some problems too when the StdElement Blocks where in a table. I tried to replace these StdCell with a new Run but when i opened it with office it is saying that the file is corrupted.


    I will try to remove Paragraph only but I was thinking that there may be some simple solution for this problem.

    Thursday, May 20, 2010 8:47 AM
  • Hi neothoms,

    Thanks for your feedback.

    For your first question, I wonder what element you are retrieving, SdtElement, SdtBlock or all the "w:sdt" elements? And could you describe a bit more about your file format which you couldn't retrieve all the blocks?

    For the second question, I think you should replace the StdCell with TableCell rather than Run. You could learn the file format by opening a Word document with the Productivity Tool.

    Hope this helps. If you have any question, please let me know.



    Friday, May 21, 2010 6:02 AM
  • Hi,


     When I try to retrieve all SdtElement (MainDocumentPart.Document.Descendants<SdtElement>), I have a strange behavior. If the element is the first, i don't know if it's the first in the line or in a paragraph, I don't have all of my blocks.

    If i make a new line before Content control i can have it in my loop.

    But what i find strange is when i tried to retrieve all SdtProperties, I found all of them MainDocumentPart.Document.Descendants<SdtProperties>()


    Friday, May 21, 2010 9:49 AM