none
Formatting unordered list (html) in altChunk RRS feed

  • Question

  • Hi all,

    The application I am working on grabs text (rich text box, multiline) from a SharePoint site, and using altChunk, inserts the content into a Word document.  So far, everything has been working fine. My problem is in the formatting of the altChunk content.

    A typical field value retrieved from the SharePoint site may look something like: <ul><li>Joseph Biden</li><li>Thomas Hanks</li><li>Lawrence Summerfield</li></ul>

    Through the use of altChunk, I generate something like this (Heading is displayed for reference, and is not part of the altChunk. It is a paragraph.):

    Heading

    • Joseph Biden
    • Thomas Hanks
    • Lawrence Summerfield

     

    There is a space (about the size of the bullet font) between Heading (a paragraph) and the unordered list (altChunk). Is there any way at all to remove/modify this space?

    Thanks!

     

    Monday, April 5, 2010 7:44 PM

All replies

  • Hi WestmereGTR,

    Thanks for your question.

    To help figure out your problem, would you please show us your content of the xml file which contatins the altChunk (I guess it's probably in /word/document.xml, you could try to open this file in the Productivity Tool)? Maybe we could see from the xml  file content where the problem is.

    Thanks,

    Lu

    Tuesday, April 6, 2010 6:32 AM
  • ...
    <w:p>
    - <w:pPr>
         <w:pStyle w:val="Style1" /> 
      </w:pPr>
    - <w:r>
         <w:t>Title</w:t> 
      </w:r>
    </w:p>
    <w:altChunk r:id="altChunk0" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" /> 
    <w:p>
    - <w:pPr>
         <w:pStyle w:val="Style1" /> 
      </w:pPr>
    - <w:r>
         <w:t>Reporting Period</w:t> 
      </w:r>
    </w:p>
    <w:altChunk r:id="altChunk1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" /> 
    ...
    

    This is a code snippet from word/document.xml. The nodes between <w:p>...</w:p> represent a simple paragraph, and is unrelated to the altChunk formatting. Style1 styles the <w:p> nodes as Bold, 13pt... it is not applied to the altChunk blocks.

    I am using this code for altChunk:

     

    string altChunkId = "tagProject";
    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, altChunkId);
    using (Stream chunkStream = chunk.GetStream(FileMode.Create, FileAccess.Write))
    using (StreamWriter stringStream = new StreamWriter(chunkStream))
    stringStream.Write(string.Format("<html><body>{0}</body></html>", content));
    AltChunk altChunk = new AltChunk();
    altChunk.Id = altChunkId;
    
    OpenXmlElement parent = alias.Parent;
    parent.InsertAfter(altChunk, alias);
    alias.Remove();

     

    where content = "<ul><li>Joseph Biden</li><li>Thomas Hanks</li><li>Lawrence Summerfield</li></ul>"

     

     

    Tuesday, April 6, 2010 1:29 PM
  • Hi WestmereGTR,

    Thanks for sharing the information.

    From your shared xml file content we can see that there is no extra paragraph between the paragraph you need to insert after and the AltChunk element. I have also run the code on a file and guess that the space is the same as that between two paragraphs. But unfortunately I don't find any property/element that could set the spacing of an AltChunk. If you save the file in Word, the AltChunk will be replaced by the content (in this case, replace as normal paragraphs), then you could set the spacing property in the ParagraphProperties as follows:

    <w:pPr>

    <w:spacing w:before="0" w:after="0"/>

    </w:pPr>

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

    Thanks,

    Lu

    Wednesday, April 7, 2010 9:47 AM
  • Hi Lu, I'm not sure what you're saying here: "... If you save the file in Word, the AltChunk will be replaced by the content (in this case, replace as normal paragraphs)... ". If I append an AltChunk to a MainDocumentPart, I can't do anything else with that AltChunk part.

    For info clarification, the reason why I'm using AltChunk is because of the <ul> tags. That's why I can't use Paragraph.

    Thanks.

    Thursday, April 8, 2010 2:19 PM
  • Hi WestmereGTR,

    Thanks for your reply.

    What I mean by the statement you mentioned is that when the Office Word application loads a document with AltChunk, it will reads the content of the imported file and replace the AltChunk in memory. Then if you choose to save this document, each <li> tag in <ul> will be replaced as a paragraph like the following format:

         <w:p w:rsidR="00000000" w:rsidRDefault="003A1EE9">
          <w:pPr>
            <w:numPr>
              <w:ilvl w:val="0" />
              <w:numId w:val="1" />
            </w:numPr>
            <w:spacing w:before="100" w:beforeAutospacing="1" w:after="100" w:afterAutospacing="1" w:line="240" w:lineRule="auto" />
            <w:divId w:val="1166089360" />
            <w:rPr>
              <w:rFonts w:eastAsia="Times New Roman" />
            </w:rPr>
          </w:pPr>
          <w:r>
            <w:rPr>
              <w:rFonts w:eastAsia="Times New Roman" />
            </w:rPr>
            <w:t>Joseph Biden</w:t>
          </w:r>
        </w:p>

     You could try it by yourself to see what happened when you save this file in Word.

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

    Thanks,

    Lu

    • Proposed as answer by Lu Zhang Thursday, April 29, 2010 7:08 AM
    Friday, April 9, 2010 5:03 AM
  • Alrighty, thanks Lu for all your help!
    Friday, April 9, 2010 12:48 PM