107
{
Microsoft.Office.Interop.Excel.Workbooks excelappworkbooks = ap.Workbo
oks;
ap.Workbooks.Open(filename,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
book = excelappworkbooks[1];
//получаем список меток документа
Microsoft.Office.Interop.Excel.Worksheet sheet = book.Worksheets[1];
this.меткиTableAdapter.Fill(this.bDDataSet1.Метки);
foreach (BDDataSet.МеткиRow m in dict.Keys)
{
//ищем нужную метку
foreach (Microsoft.Office.Interop.Excel.Name b in ap.Names)
{
if (b.Name.Equals(m.Наименование))
{
if (dict[m].GetType() == typeof(System.Windows.Forms.TextBox))
{
System.Windows.Forms.TextBox t =
(System.Windows.Forms.TextBox)dict[m];
b.RefersToRange.Value2 = t.Text;
}
else
{
////вставляем таблицу
DataGrid dgv = (DataGrid)dict[m];
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);
int row = b.RefersToRange.Row;
int col = b.RefersToRange.Column;
////заголовки колонок
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
Microsoft.Office.Interop.Excel.Range rng =
(Microsoft.Office.Interop.Excel.Range)sheet.Cells[row, i + col];
rng.Value2 = dt.Columns[i].ColumnName;
rng.Borders[XlBordersIndex.xlInsideVertical].LineStyle =
Microsoft.Office.Interop.Excel.XlLineStyle.xlDot;
rng.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle =
Microsoft.Office.Interop.Excel.XlLineStyle.xlDot;