C# exporting/merging DataGridView rows to Word Template

Your complication is actually easy however often our company require to recoil and take a breather before we may see what is actually occurring. You are assigning your variables outside of the loop and also certainly never once again. You must perform this inside the loop and also get hold of row i, certainly not Present Row.

I adhered to the directions however it carried out certainly not function in C# acquired note saying best overloaded approach match for Microsoft.Office.Interop.Word. _ Application.InchesToPoint(float) has some false arguements.

The very first row is actually repeated on the file. It will simply increase the for loop once the there are no even more areas left in the design template?

The code listed below is for exporting all rows from a datagridview table right into a word document along with combine fields. At the moment, the code listed below only duplicates the initial row in the documentation and carries out not present the remainder of the rows.

 for (int i = 0; i < gvCurrentAgreements.Rows.Count; i++)
    griddescripton = gvCurrentAgreements.Rows[i].Cells[2].Value.ToString();
    gridprice = gvCurrentAgreements.Rows[i].Cells[4].Value.ToString();
    gridquantity = Convert.ToString(gvCurrentAgreements.Rows[i].Cells[3].Value);

If you are data binding the framework I would choose using the records source over managing the framework straight.

I've begun the procedure utilizing ActiveDocument.TopMargin = but I can easily not locate the C# code similar to the vb Word.InchesToPoint(.5) Any kind of help will be considerably appreciated

 Word.Application wrdApplication = new Word.Application();
        Word.Document wrdDocument;
        wrdApplication.Visible = true;
        wrdDocument = wrdApplication.Documents.Add();
        wrdDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
        wrdDocument.PageSetup.TopMargin = wrdApplication.InchesToPoints(0.5f);
        wrdDocument.PageSetup.BottomMargin = wrdApplication.InchesToPoints(0.5f);
        wrdDocument.PageSetup.LeftMargin = wrdApplication.InchesToPoints(0.5f);
        wrdDocument.PageSetup.RightMargin = wrdApplication.InchesToPoints(0.5f);

I desire to set the margins on a Word paper I'm producing using computerization coming from code in C#.

Leave a Reply

Your email address will not be published. Required fields are marked *