none
Issue with using <w:altchunk> element in table <w:tc> element for word2007 RRS feed

  • Question

  • Hi,

    I'm using <w:altchunk> element in table <w:tc> element in document.xml. But I'm getting unspecified error. Can we put <w:altchunk> in <w:tc> element with table. I'm using following tags.

    <w:tc>

     <w:tcPr>

     <w:tcW w:w="1237" w:type="dxa"/>

     </w:tcPr>

     <w:altChunk r:id="rId88"/>

    </w:tc>

    When I place tags like this.

    <w:tc>

     <w:tcPr>

     <w:tcW w:w="1237" w:type="dxa"/>

     </w:tcPr>

    <w:p>

    <w:r>

    <w:t>

     <w:altChunk r:id="rId88"/>

    </w:t>

    </w:r>

    </w:p>

    </w:tc>

    It works fine but generating extra paragraph at the end (

    <w:p w:rsidR="006C6CE9" w:rsidRDefault="006C6CE9"/>) which makes my table column hieght larger which does not look nice.

    Please suggest me what I can do for this error or how can use altchuck so that extra paragraph should not appear.

    Thursday, March 3, 2011 5:33 AM

All replies

    • Proposed as answer by Mike_HelpYou Tuesday, March 8, 2011 7:26 AM
    • Unproposed as answer by Bruce Song Thursday, March 10, 2011 7:46 AM
    Tuesday, March 8, 2011 7:26 AM
  • Hi Mike,

    Thanks for information.

    I'm trying to show Infopath 2007 form rich text boxes data into word 2007  table.  The word doc contains a table and I've added the altchunk elements manually by editing document.xml of word. The tags as shown in my first post. The issue is that altchunk element only be used in table cell  like shown below in <w:tc>. 

    <w:tc>

     <w:tcPr>

     <w:tcW w:w="1237" w:type="dxa"/>

     </w:tcPr>

    <w:p>

    <w:r>

    <w:t>

     <w:altChunk r:id="rId88"/>

    </w:t>

    </w:r>

    </w:p>

    </w:tc>

    which results extra paragraph in table cell of document and ultimately makes  height of table cell larger. 

     When I place element like this I'm getting unspecified error.

    <w:tc>

     <w:tcPr>

     <w:tcW w:w="1237" w:type="dxa"/>

     </w:tcPr>

     <w:altChunk r:id="rId88"/>

    </w:tc>

     

    Code for creating relationship and altchunck id and rich text contents in html file are as given below.

    string wordTemplateFilePath = @"C:\Test.docx";
    string wordOutputPath = @"C:\NewDocument.docx";


    string aFChunkSchema = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk";

    // Copy the template to create a new docx file
    File.Copy(wordTemplateFilePath, wordOutputPath, true);

    Package packWordPrint = Package.Open(wordOutputPath,
    FileMode.Open, FileAccess.ReadWrite);

    Uri uri = new Uri("/word/document.xml", UriKind.Relative);
    PackagePart documentPart = packWordPrint.GetPart(uri);

    // Retrieve the XML for document.xml
    XmlDocument wordDoc = new XmlDocument();
    using (Stream s = documentPart.GetStream())
    wordDoc.Load(s);

    string altChunkId = "
    rId88";

    // Retrieve XHTML data from the RTF control
    XPathNavigator nav = MainDataSource.CreateNavigator();
    string rtf = nav.SelectSingleNode("//my:Field", NamespaceManager).InnerXml;

    rtf = "<html>" + rtf + "</html>";

    // Create the aFChunk text file
    Uri rtfUri = new Uri("/word/rtfContents.htm", UriKind.Relative);

    // Add the content type for the RTF data to [Content_Types].xml
    // in the package
    PackagePart altChunkpart = packWordPrint.CreatePart(rtfUri, "application/xhtml+xml");

    using (Stream fs = altChunkpart.GetStream())
    {
    using (StreamWriter sw = new StreamWriter(fs))
    {
    sw.WriteLine(rtf);
    sw.Close();
    }
    fs.Close();
    }


    documentPart.CreateRelationship(rtfUri, TargetMode.Internal, aFChunkSchema, altChunkId);

    packWordPrint.Flush();


    packWordPrint.Close();


    Process proc = new Process();
    proc.EnableRaisingEvents = false;
    proc.StartInfo.FileName = "winword";
    proc.StartInfo.Arguments = wordOutputPath ;
    proc.Start();

     

     Regards,

    Ranjana

     

    Wednesday, March 9, 2011 10:22 AM
  • Hi Ranjana,

    Sorry for that I am not familiar with InfoPath. Then, could you use some code to remove the paragraph mark.

    As for removeing paragraphs, please take a look at this article: http://openxmldeveloper.org/articles/395.aspx

    Hope this can help you.

    Regards,


    Be happy.
    • Proposed as answer by Bruce Song Monday, March 21, 2011 6:04 AM
    Thursday, March 10, 2011 8:04 AM