Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

I am using openxml to open and edit eh word document.

As i had also worked on Microsoft DOM component Microsoft.Office.Interop.Word
in which we can select the particular table and update the table with our new content.
likewise:

C#
 Range rng5 = adoc.Tables[24].Cell(1, 1).Range;
rng5.InlineShapes.AddPicture(@"C:\FIGURE1.JPG", ref missing, ref missing, ref missing);


Now I am doing same via openXMl where I want to do the same and select the various tables in my document.
So first of all I am unable to search the table as I am doing in my DOM coding (24)
then how do I mark the range with update code.

C#
<pre lang="xml">// Find the first table in the document.
       Table table =
           doc.MainDocumentPart.Document.Body.Elements<Table>().First();



Please assist me.

Thanks in advance..

regards
Mahendra Varandani
Posted

1 solution

C#
MainDocumentPart mainPart = doc.MainDocumentPart;

            List<sdtblock> sdtList = mainPart.Document.Descendants<sdtblock>().ToList();
            SdtBlock sdtA = null;

            foreach (SdtBlock sdt in sdtList)
            {
                var test = sdt.SdtProperties.GetFirstChild<tag>().Val.Value;
                if (sdt.SdtProperties.GetFirstChild<tag>().Val.Value == replacestring)
                {
                    sdtA = sdt;
                    break;
                }
            }
            sdtA.AppendChild(table);</tag></tag></sdtblock></sdtblock>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900