public void InsertRiskInfo(string strFileName, string strRiskScore, string iRiskCount, string iWarningCount)
        {
            object oEndofDoc = "\\endofdoc";
            Range wrdRng = doc.Books.get_Item(ref oEndofDoc).Range;
            wrdRng.InsertAfter("风险分析");
            Range tableRng = doc.Books.get_Item(ref oEndofDoc).Range;
            doc.Tables.Add(tableRng, 3, 2, ref Missing, ref Missing);
            int i = doc.Tables.Count;
            doc.Tables[i].Cell(1, 1).Range.Text = "风险总值";
            doc.Tables[i].Cell(2, 1).Range.Text = "可疑文件总数";
            doc.Tables[i].Cell(3, 1).Range.Text = "木马文件总数";
            doc.Tables[i].Cell(1, 2).Range.Text = strRiskScore;
            doc.Tables[i].Cell(2, 2).Range.Text = iRiskCount;
            doc.Tables[i].Cell(3, 2).Range.Text = iWarningCount;
            
            wrdRng = doc.Books.get_Item(ref oEndofDoc).Range;
            wrdRng.InsertAfter("\n\n\n\n\n");
        }插入表格 但是边框显示不出来 怎样设置让其显示出来啊
例外还有个问题,比如我插入一行文字:
如下:
wrdRng = doc.Books.get_Item(ref oEndofDoc).Range;
wrdRng.InsertAfter("啊啊啊啊啊");
如何设置,使得”啊啊啊啊啊“这几个字居中粗体显示

解决方案 »

  1.   

    //设置表格样式
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].Color = WdColor.wdColorAutomatic;            wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].Color = WdColor.wdColorAutomatic;            wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].Color = WdColor.wdColorAutomatic;            wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].Color = WdColor.wdColorAutomatic;            wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].Color = WdColor.wdColorAutomatic;            wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].LineWidth = WdLineWidth.wdLineWidth050pt;
                wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].Color = WdColor.wdColorAutomatic;
      

  2.   

    C#生成word.doc,word2003和wps打开,都能看到表格边框,但是word2007打开则看不到,解决办法就是
    spoonypussy的办法
    //设置表格样式
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderLeft].Color = WdColor.wdColorAutomatic;   wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderTop].Color = WdColor.wdColorAutomatic;   wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderBottom].Color = WdColor.wdColorAutomatic;   wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderHorizontal].Color = WdColor.wdColorAutomatic;   wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderVertical].Color = WdColor.wdColorAutomatic;   wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].LineWidth = WdLineWidth.wdLineWidth050pt;
       wordDoc.Tables[1].Borders[WdBorderType.wdBorderRight].Color = WdColor.wdColorAutomatic;