当前位置:编程学习 > C#/ASP.NET >>

100分求VSTO方面的问题……

asp.net生成word文档,没好说的。今天遇到一这问题:

如图1:

大家看到了,第二个表格跑到第一个表格的第一个单元格中去了………………

我要的效果:如图2:


我现在的代码,请高手分析下……

oPara1 = MyDoc.Content.Paragraphs.Add(ref missing);


                oPara1.Range.Text = documentTitle;

                oPara1.Range.Font.Bold = 1;

                oPara1.Format.SpaceAfter = 20;         //24   pt   spacing   after   paragraph.   

                oPara1.Range.Font.Size = 24;

                oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

                oPara1.Range.Font.NameFarEast = "宋体";

                oPara1.Range.InsertParagraphAfter();


                Microsoft.Office.Interop.Word.Range TwrdRng = MyDoc.Bookmarks.get_Item(ref   oEndOfDoc).Range;

                Microsoft.Office.Interop.Word.Table oTable;

                oTable = MyDoc.Tables.Add(TwrdRng, 2, 4, ref missing, ref missing);

                oTable.Range.ParagraphFormat.SpaceAfter = 15;//与下行之间的行距

                oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//表络在WORD中的对齐方式

                oTable.Range.Font.Bold = 0;

                oTable.Range.Font.Size = 10;

                oTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable.Range.Font.NameFarEast = "宋体";

                oTable.Range.Font.NameAscii = "Times New Roman";

                oTable.Range.Font.NameOther = "Times New Roman";

                oTable.Cell(1, 1).Range.Text = "团号";

                oTable.Columns[1].Width = 60;

                oTable.Cell(1, 2).Range.Text = teamNum;

                oTable.Columns[2].Width = 240;

                oTable.Cell(1, 3).Range.Text = "出团日期";

                oTable.Columns[3].Width = 60;

                oTable.Cell(1, 4).Range.Text = routedata;

                oTable.Columns[4].Width = 80;

                oTable.Cell(2, 1).Range.Text = "行程";

                oTable.Cell(2, 2).Range.Text = routeName;

                oTable.Cell(2, 3).Range.Text = "计调";

                oTable.Cell(2, 4).Range.Text = opMan;

                //oTable.Rows[1].Height = 25;

                //oTable.Rows[1].Range.Font.Bold = 1;

                //oTable.Rows[1].Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                //oTable.Rows[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;

                //合并单元格
                //oTable.Cell(1, 1).Merge(newTable.Cell(1, 3));


                ////移动焦点并换行
                //object count = 14;
                //object WdLine = Word.WdUnits.wdLine;//换一行;
                //wordApp.Selection.MoveDown(ref WdLine, ref count, ref missing);//

                //Microsoft.Office.Interop.Word.Range TwrdRng1 = MyDoc.Bookmarks.get_Item(ref   oEndOfDoc).Range;


                Microsoft.Office.Interop.Word.Table oTable1;

                oTable1 = MyDoc.Tables.Add(TwrdRng, dstroute.Tables[0].Rows.Count + 1, 8, ref missing, ref missing);

                oTable1.Range.ParagraphFormat.SpaceAfter = 6;

                oTable1.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//表络在WORD中的对齐方式

                oTable1.Range.Font.Bold = 0;

                oTable1.Range.Font.Size = 10;

                oTable1.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;//设置表格线

                oTable1.Range.Font.NameFarEast = "宋体";

                oTable1.Range.Font.NameAscii = "Times New Roman";

                oTable1.Range.Font.NameOther = "Times New Roman";


                oTable1.Cell(1, 1).Range.Text = "序号";

                oTable1.Columns[1].Width = 32;

                oTable1.Cell(1, 2).Range.Text = "游客姓名";

                oTable1.Columns[2].Width = 80;

                oTable1.Cell(1, 3).Range.Text = "英文姓名";

                oTable1.Columns[3].Width = 100;

                oTable1.Cell(1, 4).Range.Text = "性别";

                oTable1.Columns[4].Width = 40;

                oTable1.Cell(1, 5).Range.Text = "出生日期";

                oTable1.Columns[5].Width = 60;

                oTable1.Cell(1, 6).Range.Text = "护照号码";

                oTable1.Columns[6].Width = 60;

                oTable1.Cell(1, 7).Range.Text = "签发日期";

                oTable1.Columns[7].Width = 60;

                oTable1.Cell(1, 8).Range.Text = "销售";

                oTable1.Columns[8].Width = 40;

                oTable1.Rows[1].Height = 25;

                oTable1.Rows[1].Range.Font.Bold = 1;

                oTable1.Rows[1].Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                oTable1.Rows[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
//dataset填充oTable1略了……
MyDoc.SaveAs(ref docName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                
--------------------编程问答-------------------- up --------------------编程问答-------------------- 没用过。

你可以去掉些代码,看看问题出在那里。应该可以找到原因。 --------------------编程问答-------------------- LZ很强啊,帮你顶了! --------------------编程问答--------------------
引用 2 楼 XPingguo 的回复:
没用过。 

你可以去掉些代码,看看问题出在那里。应该可以找到原因。
--------------------编程问答-------------------- 专业帮顶!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,