带有边框的单词表 [英] Word table with borders
本文介绍了带有边框的单词表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码将表插入Word文档:
The following code inserts a table to the Word document:
using Word = Microsoft.Office.Interop.Word;
...
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc";
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Word.Table oTable;
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;
int r, c;
string strText;
for (r = 1; r <= 3; r++)
for (c = 1; c <= 5; c++)
{
strText = "r" + r + "c" + c;
oTable.Cell(r, c).Range.Text = strText;
}
此代码来自文章:结果是:
r1c1 r1c2 r1c3 r1c4 r1c5
r2c1 r2c2 r2c3 r2c4 r2c5
r3c1 r3c2 r3c3 r3c4 r3c5
结果表没有边框.如何更改此代码以获取带有边框的表格,如插入表格" Word命令中一样?
Resulting table doesn't have borders. How can I change this code to get a table with borders, like in "Insert Table" Word command?
推荐答案
尝试以下变体:
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
投入循环.
您还可以设置线宽和颜色:
Also you can set line width and color:
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderBottom].LineWidth = WdLineWidth.wdLineWidth050pt;
oTable.Cell(r, c).Range.Borders[WdBorderType.wdBorderBottom].Color = WdColor.wdColorRed;
这篇关于带有边框的单词表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文