Home c# Creating an Act in Word C #

Creating an Act in Word C #

Author

Date

Category

Good day. You need to create an act in Word based on data available on WinForms.
Tell me, how best to do it or where to start?
A formatted text and table will be on the sheet, the number of rows in which each time it is different, but not more than 10.
An exemplary appearance of the act can be seen in the photo below. Places where Zamazano, just need to be replaced with your own. Well, as wrote above, add rows to the table. In the original template there is only a table hat, without lines.
Enter the image description here


Answer 1, Authority 100%

Use the standard Microsoft.Office.Interop.Word extension and prepare a template from this document with bookmarks in the required locations. A brief code of work with the document:

word._document document;
Word._Application Application = New Word.Application ();
Object Missingobj = Missing.Value;
Object templatepathobj = documentpath;
// Opening a File
Try.
{
  Document = application.documents.add (Ref TemplatePathobj,
      REF MissingObj, Ref MissingObj, Ref MissingObj);
}
Catch.
{
  document.close (Ref falseobj, Ref MissingObj, Ref MissingObj);
  Application.Quit (Ref MissingObj, Ref Missingobj, Ref MissingObj);
  Document = NULL;
  Application = NULL;
}
// Filling bookmarks
Object Bookmarkobj = "Bookmark";
Word.Range BookmarkRange = Document.bookmarks.get_Item (Ref Bookmarkobj) .range;
BookmarkRange.Text = "";
// Working with the table
// Select an existing table within the document
// You can at its sequence number (starting from 1 and starting a document)
Word.Table _Table = _Document.Tables [Tablenumber];
_table.rows.add (Ref _missingobj);
Word.Range _CurrentRange = _Table.cell (Rowindex, ColumnIndex) .range;
_CurrentRange.Text = "";
// Printing
Document.Printout (Ref Missingobj, Ref Missingobj, Ref Missingobj,
    Ref MissingObj, Ref MissingObj, Ref Missingobj, Ref MissingObj,
    Ref MissingObj, Ref MissingObj, Ref Missingobj, Ref MissingObj,
    Ref MissingObj, Ref MissingObj, Ref Missingobj, Ref MissingObj,
    REF MissingObj, Ref MissingObj, Ref MissingObj);
document.close (Word.wdsaveOptions.wddonotSavechanges);
application.quit ();

In detail about this extension there is here and here .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions