Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

WPF MVVM C#

$
0
0

hi, I  am a newbie for wpf mvvm, i want to generate a report on a button click,the report consist of two tables A and B, through bookmarks in table A i have binded the properties and its working fine but as Table B is Collection of data its giving me an exception that its not able to find corresponding bookmark,so how i can resolve it and table B can be printed multiple time as per data.

the code i am using is

string docPath = "D:\\Report.docx";
            object missing = System.Type.Missing;
            Word.Application oWord = new Word.Application();
            Word.Document oWordDoc = new Word.Document();
            oWord.Visible = true;
            oWordDoc = oWord.Documents.Open(docPath);//, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
        
            PropertyInfo[] _PropertyInfos = typeof(BookMarkProperties).GetProperties();
 
            foreach (PropertyInfo propInfo in _PropertyInfos)
            {
                object oBookMark = propInfo.Name.ToString();
                oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Font.Size = 5;
                oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = propInfo.GetValue(nullnull).ToString();
              
            }
            #region run
            object oBookMark2 = "RunNumber";
            oWordDoc.Bookmarks.get_Item(ref oBookMark2).Range.Font.Size = 5;
            oWordDoc.Bookmarks.get_Item(ref oBookMark2).Range.Text = "1";
 
            for (int j = 1; j < 6; j++)
            {
                for (int i = 2; i < 13; i++)
                {
                    oWordDoc.Tables[2].Rows[i].Cells[2].Range.Text = "A-" + (i - 1).ToString() + "-" + "1";
                    oWordDoc.Tables[2].Rows[i].Cells[4].Range.Text = "A-" + (i - 1).ToString() + "-" + "2";
               }
                for (int i = 2; i < 12; i++)
                {
                    oWordDoc.Tables[2].Rows[i].Cells[6].Range.Text = "S-" + (i - 1).ToString() + "-" + "3";
                    oWordDoc.Tables[2].Rows[i].Cells[8].Range.Text = "S-" + (i - 1).ToString() + "-" + "4";
                }
            }
            oWordDoc.Tables[3].Rows.Add(ref missing);
            for (int i = 1; i < 7; i++)
            {
                oWordDoc.Tables[3].Rows[2].Cells[i].Range.Text = "B-" + i.ToString();
            }
            for (int i = 1; i < 7; i++)
            {
                oWordDoc.Tables[3].Rows[3].Cells[i].Range.Text = "C-"+i.ToString();
            }
            oWordDoc.Tables[3].Range.Copy();
            oWordDoc.Tables[3].Range.Paste();
          
            oWordDoc.Tables[3].Rows[2].Range.Copy();
            oWordDoc.Tables[3].Rows[2].Range.Paste();
 
            Clipboard.Clear();
          
        }

 

Viewing all articles
Browse latest Browse all 2535

Trending Articles



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