本帖最后由 gsdfgegasdf2 于 2014-08-05 22:11:08 编辑

解决方案 »

  1.   

          Microsoft.Office.Interop.Word.Table newTable = newdoc.Tables.Add(newapp.Application.Selection.Range, RowsCount, 2, ref nothing, ref nothing);
                    newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                    newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;                newTable.Columns[1].Width = 175f;
                    newTable.Columns[2].Width = 205f;                //第1行
                    newTable.Cell(1, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    newTable.Cell(1, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    newTable.Cell(1, 1).Range.Text = "项  目";
                    newTable.Cell(1, 2).Range.Text = "终期建设规模";
                    //文档中创建表格
                    if (rad_zl35.Checked)
                    {
                        //第2行
                        newTable.Cell(2, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(2, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(2, 1).Range.Text = "双卷边单分支";
                        newTable.Cell(2, 2).Range.Text = CommonHelper.GetNum(txt_sjbdfz_35kv.Text).ToString();                    //第3行
                        newTable.Cell(3, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(3, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(3, 1).Range.Text = "35kV线路";
                        newTable.Cell(3, 2).Range.Text = CommonHelper.GetNum(txt_35kvxl_35kv.Text).ToString();                    //第4行
                        newTable.Cell(4, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(4, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(4, 1).Range.Text = "35kV分段";
                        newTable.Cell(4, 2).Range.Text = CommonHelper.GetNum(txt_35kvfd_35kv.Text).ToString();                    //第5行
                        newTable.Cell(5, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(5, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(5, 1).Range.Text = "10kV线路";
                        newTable.Cell(5, 2).Range.Text = CommonHelper.GetNum(txt_10kvxl_35kv.Text).ToString();                    //第6行
                        newTable.Cell(6, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(6, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(6, 1).Range.Text = "10kV分段";
                        newTable.Cell(6, 2).Range.Text = CommonHelper.GetNum(txt_10kvfd_35kv.Text).ToString();                    //第7行
                        newTable.Cell(7, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(7, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(7, 1).Range.Text = "10kV电容器";
                        newTable.Cell(7, 2).Range.Text = CommonHelper.GetNum(txt_10kvdrq_35kv.Text).ToString();                    //第8行
                        newTable.Cell(8, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(8, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(8, 1).Range.Text = "接地变";
                        newTable.Cell(8, 2).Range.Text = CommonHelper.GetNum(txt_jdb_35kv.Text).ToString();                    //第9行
                        newTable.Cell(9, 1).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(9, 2).Application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        newTable.Cell(9, 1).Range.Text = "站用变";
                        newTable.Cell(9, 2).Range.Text = CommonHelper.GetNum(txt_zyb_35kv.Text).ToString();
                    }
    这个是我已经实现过了的部分代码,你可以拿来参考一下
      

  2.   

    object Anchor = newTable.Cell(2, 3).Range;
    WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);