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 .