Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

VSTO C# Tables

$
0
0

I have two word documents. Word document "A" contains a table with 5 columns and several rows. The cells within may or may not contain in line images. Word document "B" contains the same table structure but it is empty. The goal is to copy the rows (that meet a certain criteria) contain the formatted text including images from document A to the empty table, row by row, in document B.

So far this is the code I have:

 try
            {
                Word.Document sourceReport = word_app.Documents.Open(pathToPrevReport, ReadOnly: true, Visible: true);
                sourceReport.Activate();
Word.Rows sourceTable2Rows =sourceReport.Tables[2].Rows;

                
                foreach (Word.Row r in sourceTable2Rows)
                {
                    if (r.Range.Text.Contains("Open"))
                    {
                        targetTable3.Rows.Add();
                        foreach (Word.Row row in targetTable3.Rows)
                        {
                            row.Range.Text = r.Range.Text;
                        }
                    }

                }


                



                sourceReport.ActiveWindow.Close();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sourceReport);
               

            }
            catch (Exception)
            {
                
                throw;
            }

any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>