0

我有一个充满书签的单词模板,但是在尝试插入表格时我被卡住了...首先我收到了一个 COMException 说请求的集合成员不存在..我认为这意味着书签是set 的名称与我现在的表名称不同..无论如何,表格根本不显示..我在数据输入表格之前设置了格式...
像这样:

   // Insert Table


            Word.Table tbl1 = this.Tables[1];
            Tables.Add(Range: tbl1.Range, NumColumns: 2, NumRows: 2);
            tbl1.Range.Font.Size = 10;
            tbl1.Range.Font.Name = "Georgia";
            tbl1.Range.Font.Bold.Equals(true);
            tbl1.Range.Font.ColorIndex = Word.WdColorIndex.wdBlue;
            tbl1.Range.Cells.Shading.Texture = Word.WdTextureIndex.wdTexture10Percent;
            tbl1.Range.Cells.Shading.BackgroundPatternColorIndex = Word.WdColorIndex.wdBlue;
            tbl1.Range.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            tbl1.Rows.SetHeight(RowHeight: 24, HeightRule: Word.WdRowHeightRule.wdRowHeightAtLeast);
            tbl1.Columns[1].SetWidth(ColumnWidth: 170, RulerStyle: Word.WdRulerStyle.wdAdjustNone);
            tbl1.Columns[2].SetWidth(ColumnWidth: 310, RulerStyle: Word.WdRulerStyle.wdAdjustNone);
            tbl1.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
            tbl1.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;

            // end of table insert

然后填充表格的代码在......

 if (multipleLimits.Equals(false))
            {
                tbl1.Cell(1, 1).Range.Text = "Indemnity Limit:";
            }
            else
            {
                tbl1.Cell(1, 1).Range.Text = IndemlimitsText(iIndemnLimit).ToString();
            }


            switch (typeOfInsID)
            {
                case "4":
                    tbl1.Cell(1, 1).Range.Text = "Public/Products Liability:";
                    break;
            }

            tbl1.Cell(2, 1).Range.Text = "Excess:";

            if (multipleLimits.Equals(false))
            {
                tbl1.Cell(1, 2).Range.Text = sCurType + iIndemnLimit;
            }
            else
            {
                tbl1.Cell(1, 2).Range.Text = stripIndemLimitCode(iIndemnLimit).ToString();
            }

等等,等等……
我的问题是,即使没有要解析的数据,表格是否应该显示……说我是否想逐行测试解析数据?或者填充表格的代码是否需要存在并正确才能显示表格???
我希望我没有啰嗦太多,把我的问题弄糊涂了……
谢谢大家!!!

4

1 回答 1

0

答案是肯定的,表格应该显示,即使所有单元格都是空的。我想你的范围是这里的问题,因为

object endOfDoc = "\\endofdoc";
object missing = System.Reflection.Missing.Value;
string totRows = 2;
string totColumns = 2;

word.Range wrdRng = doc.Bookmarks.get_Item(ref endOfDoc).Range;
oTable = doc.Tables.Add(wrdRng, totRows, totColumns, ref missing, ref missing);

将包含 2 列和 2 行的表格添加到文档的末尾。您尝试添加到表格的范围(tbl1.Range),但这可能是表格本身内部的内部范围(可以说包含您的单元格)您想添加到段落或表格之外的其他内容。endOfDoc 是一个书签,可用于在文档末尾添加内容。

因为我不知道您使用的是什么模板,您可以先尝试一下,然后找出您需要的正确书签名称。这可以像上面代码中的 endOfDoc 一样定义,

于 2012-12-16T12:38:51.440 回答