100
document.Bookmarks[m.Наименование].Select();
Microsoft.Office.Interop.Word.Selection currentSelection = ap.Selection;
if (dict[m].GetType() == typeof(System.Windows.Forms.TextBox))
{
System.Windows.Forms.TextBox t =
(System.Windows.Forms.TextBox)dict[m];
currentSelection.TypeText(string.IsNullOrEmpty(t.Text) ? "" : t.Text);
}
else
{
//вставляем таблицу
DataGrid dgv = (DataGrid)dict[m];
document.Bookmarks[m.Наименование].Select();
System.Data.DataTable dt = (System.Data.DataTable)dgv.DataSource;
Microsoft.Office.Interop.Word.Table tbl1 =
ap.Selection.Tables.Add(ap.Selection.Range, 1, dt.Columns.Count);
//заголовки колонок
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
tbl1.Cell(1, i + 1).Range.Text = dt.Columns[i].ColumnName;
tbl1.Cell(1, i + 1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, i +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, i + 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, i +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
}
//строки таблицы
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
tbl1.Rows.Add();
for (int j = 0; j <= dt.Columns.Count - 1; j++)
{
tbl1.Cell(tbl1.Rows.Count, j + 1).Range.Text = dt.Rows[i][j] == null ? ""
: dt.Rows[i][j].ToString();
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
}
}