0

i am coding a program to print data from SQL database . this DOC files i add them bookmarks in values data . so now i have to get this data from my datagridview into the DOC file.

i tried this code :

in this code i just have 5 values . i add datagridview and fill it from SQL database and DoubleClick to add the current cell values to the textbox in my form that's all . and from the textbox.text to bookmarks in my file DOC .

object filename = @"C:\Users\Napster\Desktop\PV2016.dotx";
            object confirmConversions = Type.Missing;
            object ReadOnly = Type.Missing;
            object addToRecentFiles = Type.Missing;
            object passwordDoc = Type.Missing;
            object passwordTemplate = Type.Missing;
            object revert = Type.Missing;
            object writepwdoc = Type.Missing;
            object writepwTemplate = Type.Missing;
            object format = Type.Missing;
            object encoding = Type.Missing;
            object visible = Type.Missing;
            object openRepair = Type.Missing;
            object docDirection = Type.Missing;
            object notEncoding = Type.Missing;
            object xmlTransform = Type.Missing;
            object oMissing = System.Reflection.Missing.Value;                
            object readOnly = false;


            Microsoft.Office.Interop.Word.Application myApp1 = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document mydoc1 = new Document();

            mydoc1 = myApp1.Documents.Open(filename);

            mydoc1.Activate();
            Bookmarks bm = mydoc1.Bookmarks;

            bm.get_Item("BV_1date").Range.Text = mtb_datepostPV.Text;
            bm.get_Item("BV_fnamemply").Range.Text = mtb_fnamemplyPV.Text;
            bm.get_Item("BV_lnamemply").Range.Text = mtb_lnamemplyPV.Text;
            bm.get_Item("BV_postemply").Range.Text = mtb_postPV.Text;
            bm.get_Item("BV_service").Range.Text = mtb_servicePV.Text;
            bm.get_Item("BV_2date").Range.Text = mtb_datepostPV.Text;

this code is worked for me . but when i have a lot of columns i can't add many textboxes to my form and add the value from DataGridView to the textbox and add the textbox.text into my Doc file like what i did in the code .

Nouri Yacine
  • 63
  • 13
  • Can you clear it more for us. Because I think you can loop through your datagridview to add column. But I can't understand why you are actually doing. If you please clear more. – bluetoothfx Apr 03 '16 at 14:31
  • thank you sir i need to call date from my datagridview to the bookmarks in the DOC file . – Nouri Yacine Apr 03 '16 at 15:45
  • see the code i use it but i dont need textbox here , i want it direct from the datagridview to DOC file . like this : bm.get_Item("BV_1date").Range.Text = this.dgv_printPV.CurrentRow.Cells[0].Value.ToString(); see i transferred date from datagridview to my file . – Nouri Yacine Apr 03 '16 at 16:09

0 Answers0