none
How to add carriage return, line feed and bulleted list to Word.docx from code? RRS feed

  • Question

  • i wonder if its because of using plain text content controls instead of rt?

    but in the application it opens a word.docx as a template, its got a bunch of content controls.  based on database data and user input it fills in the cc's and sends to the users computer.  wow.

    but in one area it needs to be bulleted, and i add carriage returns in the text? but in Word they are ignored.  if my string literal text included string += "\n" then in the textareafor box? its a CRLF (return and linefeed) if i put in + 0x0a + 0x0d the hex for cr, lf ? it also returns right in the text box not in word.  format chars are ignored when it shows the formulated word doc.

    i now tried putting all of the strings into a single content control so it will shape/size right; but they run together.  i copied some text into notepad++ to discover the bullet char, copied that into the code for + "?" whatever the symbol is and it causes a thin lined box instead of a filled in bullet.  no return.

    Not sure what to be adding in there to format the data??

    Thursday, July 23, 2015 8:51 PM

All replies

  • Hi Bradley

    Yes, it's partly due to using plain CC. A plain CC can't contain a carriage return (ANSI 13; \r). It can contain new lines (ANSI 11; ? \v ?), but a property must be set in order to allow that, which is the Multiline attribute of SdtContentText:

    https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sdtcontenttext%28v=office.14%29.aspx?f=255&MSPPError=-2147217396
    https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sdtcontenttext.multiline(v=office.14).aspx

    If you need bulleted text, then you need a rich text CC.

    Set up a simple test document then look at it in the Open XML SDK Productivity Tool.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 24, 2015 3:57 PM
    Moderator
  • Hi Cindy 

    thanks thats very helpful.  i changed to richtext cc's 

    yes using the productivity tool i can see breaks in there <br /> but word ignores them, will try some more

    Friday, July 24, 2015 4:16 PM
  • Hi Bradley

    Productivity Tool: to see the multiline attribute and to see how bullets are handled...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 24, 2015 6:29 PM
    Moderator
  • Cindy

    Im not sure if my word doc is even making a richtext box.  im looking at the links trying to find a way to force multiline=true

    i tried to open my docx in visual studio and it crashed it.  Eric White who writes alot of openxml has a video doing this, drag the .docx file into visual studio to see the xml and be able to edit it.  the productivity tool cannot edit, at least the one i have cannot

    i hoped if i could just edit the word doc and force multiline is true then this horrible mess would be solved

    Friday, July 24, 2015 6:38 PM
  •   foreach (var cc in wordDoc.ContentControls())
                        {
                            SdtProperties props = cc.Elements<SdtProperties>().FirstOrDefault();
                            SdtContentText sct = cc.Elements<SdtContentText>().FirstOrDefault();
                            if (sct != null)
                            {
                                sct.MultiLine.Value = true;
                            }

    here is one approach, but its no different, sct is always null, this is from the linked reference in your last post, 

    SdtContentText.MultiLine Property 

    [SchemaAttrAttribute(, "multiLine")] public OnOffValue MultiLine { get; set; }

    does not work

    Friday, July 24, 2015 7:09 PM
  • its how it is, visual studio crashes when trying to open any .xml file

    File/ New/ file: xml file

    bottom left:  waiting for parse to complete

    popup: microsoft visual studio    opening the file ...   [green flows left to right endlessly]

    task manager... close.. microsoft visual studio has stopped responding  checking for a solution... restarting  tried new html and it opens.  HAD to try it.  open new xml, crash.

    Friday, July 24, 2015 7:16 PM
  • Hi Cindy

    i added the multiline directly into the word document by way of visual studio.  (only had to reboot the pc and start things over), but one thing visual studio doesnt hog the file where sdk productivity tool does.  if its open in visual studio you can save changes, open in word and see, save there go back to VS and it will say the file changed, see changes?  

    but if you looked at this, would you assume multi line is set?  i had added the multiline=true based on your link, saved the word docx, opened again and it moved it down a bit and changed the true to =1.   Now it seems to be multi line.  And in the properties? it changed the properties dialog

    <w:sdt>
                  <w:sdtPr>
                    <w:rPr>
                      <w:b w:val="0" />
                      <w:sz w:val="24" />
                      <w:szCs w:val="24" />
                    </w:rPr>
                    <w:tag w:val="custmile1" />
                    <w:id w:val="-648628776" />
                    <w:placeholder>
                      <w:docPart 
    w:val="3C4FD25A33411B5077C8C3F7BCA63CBA" />
                    </w:placeholder>
                    <w:showingPlcHdr />
                    <w:text w:multiLine="1" />
                  </w:sdtPr>

    now it says:

    this is a Rich text content control.  i deleted and re put rich text several times.  when i modified the values? then went back in, then it has this box.  why isnt this always in EVERY property  box?

    then in the text?  when its fed into the html textbox (text area for) its nice and formatted with 2 line feeds.  in word?  NO CRLF, never line feeds, ever.


    Friday, July 24, 2015 8:19 PM
  • Hi Bradley

    Productivity Tool: to see the multiline attribute and to see how bullets are handled...


    Cindy Meister, VSTO/Word MVP, my blog

    Hi Cindy

    im setting a static string variable =" "; then assigning it the db value and adding in the other characters, so its sometimes string = "\n" + dbvalue...

    when I use the Tab char? string = "\t" + dbvalue...  word sees and applies the tab.  but i have tried "\n\r" dont know what else to try

    Saturday, July 25, 2015 12:16 AM
  • Hi Bradley

    From my original reply in this thread:

    "Yes, it's partly due to using plain CC. A plain CC can't contain a carriage return (ANSI 13; \r). It can contain new lines (ANSI 11; ? \v ?), but a property must be set in order to allow that, which is the Multiline attribute of SdtContentText:"


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, July 26, 2015 4:13 PM
    Moderator
  • Hi Cindy

    no, i have used plain text and rich text.  i cannot see any difference in anything within word that would suggest they are different.  i add plan or rich text cc and the same exact cc appears, no different properties, no different shape, nothing that even says plain or rich text cc.    but i added multi line =1  no effect

    how could i even tell if its a rich text cc ???????  i wrote that i have deleted and re placed clicking rich text, no change.

    i can insert the tab char? and word applies it.  i put some ascii char i copied from a bullet and word puts a basic square bullet.  at no time is any code text or escape sequence making  a CRLF in word, but it MUST.

    i tried with word 2015, brand new install and it made no difference, if this isnt a bug?  i "will eat my sunday hat".  there is no code left to try, it cannot be done.  I reached out to Eric White hoping he might have some wild guess to try.    if I knew the answer to a serious question someone struggled with day after day, Id help them.  i know youre trying and i appreciate it.

     i add a sentence then crlf chars then a sentence and crlf look in the xml of word and its a sentence then some O with a line thru it, sentence O with line thru it, assuming thats the bullet char.

    maybe im the first person to ever insert bulleted sentences from openxml into word .docx and am the first one to discover it doesnt work and cannot be done

    Monday, July 27, 2015 12:24 AM
  • Hi Bradley,

    >>how could i even tell if its a rich text cc ???????  <<

    Open XML use sdt XML element to represent the plain text and rich text box. If there is an text element under the sdtPr, then this is plain text content control. Here is the a snippet for the XML of plain text content control for your reference:

    <w:sdtPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
      <w:id w:val="-1402511907" />
      <w:placeholder>
        <w:docPart w:val="DefaultPlaceholder_1081868574" />
      </w:placeholder>
      <w:text w:multiLine="1" />
    </w:sdtPr>

    >>i tried with word 2015, brand new install and it made no difference, if this isnt a bug?  i "will eat my sunday hat".  there is no code left to try, it cannot be done.<<

    Can you add carriage return, line feed and bulleted list in Word 2015 manually? If it is ok, we can use open XML SDK 2.5 Productivity Tool as Cindy suggested to refect the code for the reference.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, July 27, 2015 5:56 AM
    Moderator
  • i make a new word doc like this:

    Sentence 1.

    One cr.

    Two cr.

    Four cr.

    • B list1
    • B list2

    then in the sdk tool,

    <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="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:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" 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:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
      <w:body>
        <w:p w:rsidR="00D04E42" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:r>
            <w:t>Sentence 1.</w:t>
          </w:r>
        </w:p>
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:r>
            <w:t>One cr.</w:t>
          </w:r>
        </w:p>
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7" />
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:r>
            <w:t>Two cr.</w:t>
          </w:r>
        </w:p>
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7" />
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:bookmarkStart w:name="_GoBack" w:id="0" />
          <w:bookmarkEnd w:id="0" />
        </w:p>
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7" />
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:r>
            <w:t>Four cr.</w:t>
          </w:r>
        </w:p>
        <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:pPr>
            <w:pStyle w:val="ListParagraph" />
            <w:numPr>
              <w:ilvl w:val="0" />
              <w:numId w:val="4" />
            </w:numPr>
          </w:pPr>
          <w:r>
            <w:t>Blist1</w:t>
          </w:r>
        </w:p>
        <w:p w:rsidRPr="004A01E7" w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
          <w:pPr>
            <w:pStyle w:val="ListParagraph" />
            <w:numPr>
              <w:ilvl w:val="0" />
              <w:numId w:val="4" />
            </w:numPr>
          </w:pPr>
          <w:r>
            <w:t>Blist2</w:t>
          </w:r>
        </w:p>
        <w:sectPr w:rsidRPr="004A01E7" w:rsidR="004A01E7">
          <w:pgSz w:w="12240" w:h="15840" />
          <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
          <w:cols w:space="720" />
          <w:docGrid w:linePitch="360" />
        </w:sectPr>
      </w:body>
    </w:document>

    so to me, it looks like the CRLF is: 

     <w:p w:rsidR="004A01E7" w:rsidP="004A01E7" w:rsidRDefault="004A01E7">
         

    so then insert a paragraph between each line?

       Paragraph[] paragraphs = new Paragraph[4];
    
                        foreach (var cc in wordDoc.ContentControls())
                        {Tag tag = props.Elements<Tag>().FirstOrDefault();
                            
                           // richTextBox1.Text += "new data is: " + tag.Val + "\n";
                            dat1 = tag.Val.ToString();
                         switch  (dat1)
                         { case "custmile1":
                                 paragraphs[0] = new Paragraph(new ParagraphProperties(new NumberingProperties(new NumberingLevelReference { Val = 0 }, new NumberingId { Val = 1 })), new Run(new RunProperties(), new Text(custmiles1) { Space = SpaceProcessingModeValues.Preserve }));
                                 paragraphs[1] = new Paragraph(new ParagraphProperties(new NumberingProperties(new NumberingLevelReference { Val = 0 }, new NumberingId { Val = 1 })), new Run(new RunProperties(), new Text(custmiles2) { Space = SpaceProcessingModeValues.Preserve }));
                                 paragraphs[2] = new Paragraph(new ParagraphProperties(new NumberingProperties(new NumberingLevelReference { Val = 0 }, new NumberingId { Val = 1 })), new Run(new RunProperties(), new Text(custmiles3) { Space = SpaceProcessingModeValues.Preserve }));
                             

    and then the resulting word doc: edit: surprised its got the xml tags in there, just copied it from word

    <w:sdt docpart="7DFFFB93CD66455185F9DCB2C9224C87" id="-635173476" multiline="t" sdttag="custmile1" showingplchdr="t" text="t">DocumentFormat.OpenXml.Wordprocessing.ParagraphDocumentFormat.OpenXml.Wordprocessing.ParagraphDocumentFormat.OpenXml.Wordprocessing.Paragraph  </w:sdt>


    Monday, July 27, 2015 1:01 PM
  • http://stackoverflow.com/questions/1940911/openxml-2-sdk-word-document-create-bulleted-list-programmatically

    here is some more info

    Monday, July 27, 2015 2:09 PM
  • Hi Bradley

    Third time's a charm? READ it:

    "...A plain CC can't contain a carriage return (ANSI 13; \r). It can contain new lines (ANSI 11; ? \v ?), ..."


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 27, 2015 2:22 PM
    Moderator
  • Cindy

    I thought i had mentioned, "/v" also was no good, when trying to use this it gets this error: 

    '', hexadecimal value 0x0B, is an invalid character.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.ArgumentException: '', hexadecimal value 0x0B, is an invalid character.
    I can add this inside the case, or add it when loading the string variable.  any hint of "\v" and it crashes;  

    Monday, July 27, 2015 3:35 PM
  • this is the part i am trying to also do in parallel because "\v" does not work, and i tried it more than 3 times?

    it ends up with this "element" at the bottom that Im trying to prybar in to the content control

    So to create a bullet list such as: Hello, world! You would first have to create a NumberingDefinitionsPart: NumberingDefinitionsPart numberingPart = mainDocumentPart.AddNewPart<NumberingDefinitionsPart>("someUniqueIdHere"); Numbering element = new Numbering( new AbstractNum( new Level( new NumberingFormat() {Val = NumberFormatValues.Bullet}, new LevelText() {Val = "·"} ) {LevelIndex = 0} ){AbstractNumberId = 1}, new NumberingInstance( new AbstractNumId(){Val = 1} ){NumberID = 1}); element.Save(numberingPart); Then you create the MainDocumentPart as you normally would, except in the paragraph properties, assign the numbering ID: MainDocumentPart mainDocumentPart = package.AddMainDocumentPart(); Document element = new Document( new Body( new Paragraph( new ParagraphProperties( new NumberingProperties( new NumberingLevelReference(){ Val = 0 }, new NumberingId(){ Val = 1 })), new Run( new RunProperties(), new Text("Hello, "){ Space = "preserve" })), new Paragraph( new ParagraphProperties( new NumberingProperties( new NumberingLevelReference(){ Val = 0 }, new NumberingId(){ Val = 1 })), new Run( new RunProperties(), new Text("world!"){ Space = "preserve" })))); element.Save(mainDocumentPart);


    Monday, July 27, 2015 3:39 PM
  • Hi Bradley

    OK, looking at the XML in document.xml of a content control with multiline active and a newline character (ANSI 11), this is what I see

    <w:sdtContent>
    	<w:r >
    		<w:t>test</w:t>
    	</w:r>
    	<w:r >
    		<w:br/>
    	</w:r>
    		<w:t>1</w:t>
    	</w:r>
    </w:sdtContent>
    

    It appears not to accept a text character - it wants a <w:br/>.

    https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.break%28v=office.14%29.aspx?f=255&MSPPError=-2147217396

    For an example of its use:

    http://stackoverflow.com/questions/2871887/inserting-newlines-in-word-using-openxml


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 27, 2015 3:50 PM
    Moderator
  • made it work but not like the example, not like i thought it would be but solid
    Monday, July 27, 2015 5:54 PM
  • Cindy that was helpful i found a way to cause the crlf, tried to post but kept getting errors as i posted anything.

    there is a bullet that i add as a char but then if that line wraps around?  it goes to the far left margin, no padding at all   so the bullet, a few spaces, then text.  it will crlf at the end but text running too far wraps and doesnt stay in the text margin so its not useable.

    Tuesday, July 28, 2015 3:52 AM
  • Hi Bradley,

    Which content control are you using, plain text or rich text?Based on the test, I am able to only one bullet for the plain text content control.And the richtext works well. Here is the figure fore your reference:

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 28, 2015 6:05 AM
    Moderator
  • HI Fei,

    I have been trying to use rich text cc's but there is no visual difference in trying rich vs plain.  i delete the cc, then click rich text cc and add its name;  it seems as if the rich text cc might have some way to indicate its rich vs plain??  i cannot tell.  i try rich.

    looking at the productivity tool there is no difference in xml between the 2 controls.  so how does Word tell?  

    here i type in a return b return c return and in the rich text it does what it shows, click bullets and its there.  plain, as we know, will not accept cr's

    making the rich text CC with  a type of font set to bullet list, then adding text, makes one bullet with all the sentences together


    Tuesday, July 28, 2015 12:41 PM
  • apparently when you databind a content control it defaults to plain text CC

    http://openxmldeveloper.org/discussions/development_tools/f/17/p/7264/162455.aspx

    so trying to add newlines to the cc?  it would secretly become a plain text cc, at least this is what appears to be the case.

    Tuesday, July 28, 2015 1:35 PM
  • <<looking at the productivity tool there is no difference in xml between the 2 controls.  so how does Word tell? >>

    Look again, very carefully - I see it. See:

    https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sdtcontenttext(v=office.14).aspx


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 28, 2015 3:40 PM
    Moderator
  • <w:p w:rsidR="00360529" w:rsidP="00360529" w:rsidRDefault="00360529">
    
    
    <w:p w:rsidRPr="00360529" w:rsidR="00360529" w:rsidP="00360529" w:rsidRDefault="00360529">

    one rich one plain

    <w:p      >
    
    
    <w:p w:rsidRPr="00360529"     >
    RsidRPr

    Physical Section Mark Character Revision ID.Represents the attribte in schema: w:rsidRPr

    aside from this, i do not see any xml difference.  

    just need bulleted text that works

    Tuesday, July 28, 2015 3:53 PM
  • Rich:

        <w:sdtPr>
          <w:id w:val="-1412845767" />
          <w:placeholder>
            <w:docPart w:val="DefaultPlaceholder_1082065158" />
          </w:placeholder>
        </w:sdtPr>
    

    Plain:

      <w:sdt>
        <w:sdtPr>
          <w:id w:val="-1885240554" />
          <w:placeholder>
            <w:docPart w:val="DefaultPlaceholder_1082065158" />
          </w:placeholder>
          <w:text />
        </w:sdtPr>

    Refer to the link in my previous reply re <w:text />, which is the difference between the two, and consult the Productivity Tool.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 28, 2015 4:56 PM
    Moderator
  • i read the link very carefully, and read other similar links.  i carefully compared the two based on the productivity tool.  in my system there is NOT a 

    <w:text />

    there is only w:t in both plain and rich text cc's. i compared letter for letter, symbol for symbol. the id value numbers like 00539439 i disregard

    now i cant even put text outside this code section thing. its a conspiracy.

    Tuesday, July 28, 2015 5:12 PM
  • maybe the answer would be to use a textbox instead of content control, whatever it takes to put this data there and go
    Tuesday, July 28, 2015 5:22 PM
  • Either you're looking in the wrong place in the XML (you need to go higher up, before the <p><r><t> section), or you've inserted two Richtext content controls.

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 28, 2015 6:41 PM
    Moderator
  • so I think that if its w:text to define the plain cc?  which is what i found in my main template document, after making sure they were all , ALL rich text cc's;  something changes them, silently, into plain text cc's that much is absolutely certain.  

    but ok i can leave that for now do you have any ideas on bulleted text? i use the mechanism to write text then say cc.appendchild(new break()) and it makes the crlf in the word doc.

    but once it wraps? it goes to the left edge.  i have tried manually generating a paragraph with the text and bullet formatting, but while it "lets me" prybar it in the word doc, making a corrupt file that wont open

    have tried many mechanisms to make styles and add the bullet.  

    Tuesday, July 28, 2015 7:16 PM
  • Hi Bradley

    <<apparently when you databind a content control it defaults to plain text CC>>

    Not all versions of Word can databind to a RichText content control (new in 2013). If you're targeting 2013 (and later) then the Settings in the Open XML need to be specific for 2013 - the default will be compatible for 2007.

    <<do you have any ideas on bulleted text?>>

    Not specifically in Word Open XML, but I can explain a few things...

    1. You can't use bullets inside a plain text CC. Bullets are formatting = Rich text.

    2. If I've understood something you've said correctly, you're trying to "mimic" bullets with a symbol, inside a plain text CC. The problem being you're not getting a hanging indent. There's no way to solve this - short of forcing line breaks in place of Word's automatic wrapping - since a hanging indent requires a <p> and a plain text CC cannot contain a <p>.

    3. A possible work-around could be to use a plain text CC for each bullet point, then the formatting is applied to the <p> in which the content control is positioned.

    4. Applying/generating bullet formatting: I'd create styles for both the bullets and the paragraph formatting and link the two. Assigning the paragraph style to text should automatically bring in the bullets. You should be able to get the XML / Open XML code for this by creating them in a document then using the Productivity Tool.

    It would help immensly if people working with this would all have to start with a given document that could already contain these styles, so you wouldn't have to create them in your code from scratch.

    If that's not possible, my inclination would be to have a resource file (XML) containing the Word Open XML for such "items". It would be a fairly simple matter to "copy" the XML and assign it to the InnerXML property of an element, rather than having to code it all (and probably faster in execution).


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 28, 2015 8:32 PM
    Moderator
  • Cindy

    i tried making the bulleted char in their own cc.  came out identical

    when i sort thru the content controls and find the name that matches, how can i just insert a whole new paragraph there?  one that has the formatting and the text?

    i try and it corrupts the docx file.

    Tuesday, July 28, 2015 9:24 PM
  • now at the home pc i cannot open word docs anymore.  it makes word open them.  i just wanted to open like before to edit the xml in visual studio.  no matter what i try it opens in word.

    17.5.2.26 richText (Rich Text Structured Document Tag)

    This element specifies that the parent structured document tag shall be a rich text box when displayed in the document.

    If no type element (the xsd:choice block in the XML Schema fragment for the parent sdtPr element) is specified, then the parent structured document tag shall be of type richText.

    [Example: Consider the following structured document tag:

    <w:sdt> <w:sdtPr>
    <w:richText/> </w:sdtPr>
    </w:sdt>

    The richText element in this structured document tag's properties specify that the type of structured document tag is a rich text box. end example].

    wanted to try putting in the w:richText

    cant.  too bad the "productivity" tool will not edit.

    Tuesday, July 28, 2015 11:36 PM
  • Hi Bradley,

    >>wanted to try putting in the w:richText cant.  too bad the "productivity" tool will not edit.<<

    If there is no type element in the sdtPr, the content control is rich text box control. Only we assign the child node <w:text /> for the sdtPr element then it became be plain text control.

    If you want to use bullets in content control, I suggest that you use rich text content control.

    >>too bad the "productivity" tool will not edit.<<

    To edit the xml of Office document, we can change the extension to Zip and copy the xml and modify it.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 29, 2015 2:14 AM
    Moderator
  • Hi Fei

    If you want to use bullets in content control, I suggest that you use rich text content control.

    but i have tried every way i can think of, it simply will not work.  it appears the paragraph has to be manually built with custom settings.  this is a "near" bug because it should work but doesnt but is more of a useage concern than just a bug.  

    i downloaded the altonova ? xml spy tool 30 day trial to get in to the file, i could not make the zip work on this pc.  just trying to get it done before tomorrow.  

    will try to insert the manually created pragraph with bullet there. 

    Wednesday, July 29, 2015 2:33 AM
  • Hi Bradley

    It is simply not possible to "append" a bullet to a paragraph. Word doesn't work that way; if you try to force it to do something not supported by the underlying schema you're going to get a damaged file.

    My recommendation would be to create two very simple documents, exactly the same, except that in the one you've applied bullet formating to a rich text content control. Then use the Productivity Tool to COMPARE them - that will show you what's required.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, July 29, 2015 2:33 PM
    Moderator
  • HI Cindy

    well its closer, i tried creating the paragraph list programatically, but when inserted in the doc its corrupted; i can delete some other paragraphs/runs and save and it opens and i can see the bullet list.  

    but for now? a different question maybe you can answer or anyone can answer, i am using the bulleted content controls.  the next content control has text wrap around.

    the user will need to just edit it manually, which is very bad.  but guess what?  Word will not let the text get changed!  how can this be over ridden?  

           the text runs to the end and wraps around here,

    now on the next line, 'now' will not move.  period end of discussion.  try to add spaces? it sits there broken.  ive seen word do this, usually when making reports in a frantic hurry when they are due in 10 minutes?   the outrage is off the scale.  i want to insert &*(*^^% spaces in there!!! why is it refusing?  please help!!!

    Wednesday, July 29, 2015 7:16 PM
  • i do not know why but i have 8 content controls.  all unique.  but word treats them as one unit.  they move together, select text in all and hit bullet and only 1 bullet.

    as of now the user cannot even force the bullets into the text manually.

    in each content control i clicked the 'delete content control when modified' hoping it would leave text behind.  no, its not deleted   

    i need a new solution within 15 minutes

    Wednesday, July 29, 2015 7:31 PM
  • Hi Bradley,

    The suggestion provide by Cindy to compare the difference for the documents is very helpful. And also we can reflect the code using Open XML SDK 2.5 Productivity Tool.

    Here is an sample that creating an document which contained rich text content control with three paragraphs format with bullets:

         public void InsertRichTextCC()
            {
                string docName = @"C:\doc1.docx";
                using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
                {
                    // Add a new main document part. 
                    package.AddMainDocumentPart();
    
                    Body body = new Body();
                    body.Append(GenerateSdtBlock());
                    // Create the Document DOM. 
                    package.MainDocumentPart.Document =
                      new Document(body);
    
                    // Save changes to the main document part. 
                    package.MainDocumentPart.Document.Save();
                } 
    
            }
    
            public SdtBlock GenerateSdtBlock()
            {
                SdtBlock sdtBlock1 = new SdtBlock();
    
                SdtProperties sdtProperties1 = new SdtProperties();
                SdtId sdtId1 = new SdtId() { Val = -206335861 };
    
                SdtPlaceholder sdtPlaceholder1 = new SdtPlaceholder();
                DocPartReference docPartReference1 = new DocPartReference() { Val = "DefaultPlaceholder_1081868574" };
    
                sdtPlaceholder1.Append(docPartReference1);
    
                sdtProperties1.Append(sdtId1);
                sdtProperties1.Append(sdtPlaceholder1);
    
                SdtContentBlock sdtContentBlock1 = new SdtContentBlock();
    
                Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00816E2A", RsidParagraphProperties = "00816E2A", RsidRunAdditionDefault = "00816E2A" };
    
                ParagraphProperties paragraphProperties1 = new ParagraphProperties();
                ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() { Val = "ListParagraph" };
    
                NumberingProperties numberingProperties1 = new NumberingProperties();
                NumberingLevelReference numberingLevelReference1 = new NumberingLevelReference() { Val = 0 };
                NumberingId numberingId1 = new NumberingId() { Val = 1 };
    
                numberingProperties1.Append(numberingLevelReference1);
                numberingProperties1.Append(numberingId1);
                Indentation indentation1 = new Indentation() { LeftChars = 0 };
    
                paragraphProperties1.Append(paragraphStyleId1);
                paragraphProperties1.Append(numberingProperties1);
                paragraphProperties1.Append(indentation1);
    
                Run run1 = new Run();
                Text text1 = new Text();
                text1.Text = "A";
    
                run1.Append(text1);
    
                paragraph1.Append(paragraphProperties1);
                paragraph1.Append(run1);
    
                Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00816E2A", RsidParagraphProperties = "00816E2A", RsidRunAdditionDefault = "00816E2A" };
    
                ParagraphProperties paragraphProperties2 = new ParagraphProperties();
                ParagraphStyleId paragraphStyleId2 = new ParagraphStyleId() { Val = "ListParagraph" };
    
                NumberingProperties numberingProperties2 = new NumberingProperties();
                NumberingLevelReference numberingLevelReference2 = new NumberingLevelReference() { Val = 0 };
                NumberingId numberingId2 = new NumberingId() { Val = 1 };
    
                numberingProperties2.Append(numberingLevelReference2);
                numberingProperties2.Append(numberingId2);
                Indentation indentation2 = new Indentation() { LeftChars = 0 };
    
                paragraphProperties2.Append(paragraphStyleId2);
                paragraphProperties2.Append(numberingProperties2);
                paragraphProperties2.Append(indentation2);
    
                Run run2 = new Run();
                Text text2 = new Text();
                text2.Text = "B";
    
                run2.Append(text2);
                BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
                BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };
    
                paragraph2.Append(paragraphProperties2);
                paragraph2.Append(run2);
                paragraph2.Append(bookmarkStart1);
                paragraph2.Append(bookmarkEnd1);
    
                Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00546790", RsidParagraphProperties = "00816E2A", RsidRunAdditionDefault = "00816E2A" };
    
                ParagraphProperties paragraphProperties3 = new ParagraphProperties();
                ParagraphStyleId paragraphStyleId3 = new ParagraphStyleId() { Val = "ListParagraph" };
    
                NumberingProperties numberingProperties3 = new NumberingProperties();
                NumberingLevelReference numberingLevelReference3 = new NumberingLevelReference() { Val = 0 };
                NumberingId numberingId3 = new NumberingId() { Val = 1 };
    
                numberingProperties3.Append(numberingLevelReference3);
                numberingProperties3.Append(numberingId3);
                Indentation indentation3 = new Indentation() { LeftChars = 0 };
    
                paragraphProperties3.Append(paragraphStyleId3);
                paragraphProperties3.Append(numberingProperties3);
                paragraphProperties3.Append(indentation3);
    
                Run run3 = new Run();
                Text text3 = new Text();
                text3.Text = "C";
    
                run3.Append(text3);
    
                paragraph3.Append(paragraphProperties3);
                paragraph3.Append(run3);
    
                sdtContentBlock1.Append(paragraph1);
                sdtContentBlock1.Append(paragraph2);
                sdtContentBlock1.Append(paragraph3);
    
                sdtBlock1.Append(sdtProperties1);
                sdtBlock1.Append(sdtContentBlock1);
                return sdtBlock1;
            }

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 30, 2015 6:38 AM
    Moderator
  • Hi Fei

    I stayed on this until the middle of the nite to make the append paragraph work, 

    Paragraph p = GenerateParagraph(custmilestone1);
    cc.ChildElements.GetItem(1).Append(p);
    

     and in the document, its showing up.  it does have numbers instead of bullets;  if i set the type to make bulleted list? the text wraps around wrong, as always.  if numbered list? it keeps the text as it should be.  why would it do this?

    but even WORSE is the fact the resulting text is LOCKED OUT from the user.  its there, you can select and you can copy it, but its locked from any changes.  Why does word do this?  it is a hard requirement that the user can edit this simple data.  

    here is how it looks:

    *   this is the first sentence that

    wraps around wrong to the left edge

    *  this is the second sentence.

    // now setting it to numbers instead of bullet:

    1.  this is the first sentence that

         wraps around correctly.

    2.  this is the second sentence

    so I have to change it to use numbers, which we dont want;  but the text is locked, it must be unlocked.  i will try with your example now

    thanks

    Thursday, July 30, 2015 2:23 PM
  • Hi Fei

    i was able to use your code and get this to insert, THANKS! but notice the large bold font.  in this are it used 1. with the correct 12pt plain but the rest is large/bold.  and this is editable.  I have gone back in to the template doc (several times) and carefully tried to check every bit for font, making it all 12pt plain.  it runs and comes back as above, any idea?

    thanks

    Thursday, July 30, 2015 3:46 PM
  • well it doesnt run anymore.  no idea why.

    it simply throws an exception Exception Details: System.InvalidOperationException: Non-composite elements do not have child elements.

    same code that worked, now doesnt work

    case "custmiles":
         cc.NextSibling().AppendChild(GenerateSdtBlock());
    I had the font solved by forcing the font settings in there. worked fine.  as i added more font info it just started throwing this error above.  backed off all changes.  once i use generatesdtblock(), its done 

    Thursday, July 30, 2015 8:39 PM
  • Hi Bradley,

    The code provided in the previews post doesn't apply the bold font for the words. Would you mind sharing the code if you changed it?

    Here is a figure for the correct result:

    In addition, since the post is too long, I would suggest that you reopen a new thread to involve more communities if you have any other issues so that you can get more effective response.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 31, 2015 2:29 AM
    Moderator
  • Hi Fei,

    for now, if you can please answer about your code,  I am trying to add a CRLF to put padding, to make the section fit.  there must be one linefeed.

    if I put into the code:  append(new break()); and i have tried before the append of text in several places, the result is:

                      The title of the document
    1.
           this is the first sentence
    2.     this is the 2nd sentence
    3.     this is 3rd

    nothing has effect on the list items. 


    Friday, July 31, 2015 3:36 PM
  • i solved the spacing part, put the title into a single element table and expanded it out.

    but now the problem is the left margin spacing

    Friday, July 31, 2015 3:44 PM
  • where the code says: 

                numberingProperties1.Append(numberingLevelReference1);
                numberingProperties1.Append(numberingId1);
                Indentation indentation1 = new Indentation() { LeftChars = 50 };
    

    when 50 is added there, it means probably about 3 or 4 character spaces.  putting 5 in there didnt get noticed.

    now? 

    1.   this is the first sentence

    2.   this is the 2nd sentence

    3.   this sentence wraps around...

             and the text does not line up, its farther in.

    Friday, July 31, 2015 4:00 PM
  • so using a different method to go to parts of the document i inserted the new entire sdt, and making changes to the sdt details, it lines up and can be edited in the final document

    no combination of integers makes it show bullet points.  its numbers or its nothing.  no roman numerals no nothing else.  

    cartoon somewhere, older ones, people leave the house and the cat is there, lots of cat food cans but no opener.  looks everywhere,  mouse whistles and swings the opener, cat chases him (could be Tweety bird?)  the cat goes thru all this misery to finally somehow, amazingly end up with the can opener, and then?  finds the cabinet locked.  mouse or tweety whistles and swings the key. cat is flummoxed in disbelief.

    now on to the next section.  

    Sunday, August 2, 2015 3:44 AM
  • Hi Bradley,

    Hi Fei,

    for now, if you can please answer about your code,  I am trying to add a CRLF to put padding, to make the section fit.  there must be one linefeed.

    if I put into the code:  append(new break()); and i have tried before the append of text in several places, the result is:

                      The title of the document
    1.
           this is the first sentence
    2.     this is the 2nd sentence
    3.     this is 3rd

    nothing has effect on the list items. 


    I am not able to understand the secnario section fit exactly. Did you mean you want to append some text? Which type of content control are you using? It is appreciate that if you can upload a document and the code to help us peproduce this issue.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 3, 2015 9:51 AM
    Moderator