微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

互操作词:有没有办法将多个表格或段落添加到表格单元格中而不将它们合并在一起?

如何解决互操作词:有没有办法将多个表格或段落添加到表格单元格中而不将它们合并在一起?

我在向表格单元格添加多个段落或表格时遇到问题。它们都融合在一起。

[结果]

1

  • 我希望我的两个表格一个一个,而不是合并到我的单元格范围内
  • 我希望将红色文本(我在 word 中放入红色)作为我的表格标题,我之前在代码添加了它,但它仍然出现在之后。

这是我的代码

Paragraph pBT_Text = document.Paragraphs.Add(cell.Range);
pBT_Text.Range.Font.Bold = 1;
pBT_Text.Range.Font.Size = 7;
pBT_Text.Range.Font.Underline = WdUnderline.wdUnderlinesingle;
pBT_Text.Range.Text = "x-content";
pBT_Text.Range.InsertParagraphAfter();

Paragraph pIntroTable_BT = document.Paragraphs.Add(cell.Range);
Table Bt_Tech_Table = document.Tables.Add(pIntroTable_BT.Range,5,7,ref missing,ref missing);
Bt_Tech_Table.Borders.Enable = 1;
Bt_Tech_Table.Range.Font.Underline = WdUnderline.wdUnderlineNone;
Bt_Tech_Table.Range.Paragraphs.Alignment = WdParagraphAlignment.wdalignParagraphCenter;
Bt_Tech_Table.AllowAutoFit = true;

Bt_Tech_Table.Rows[1].Cells[1].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[1].Shading.BackgroundPatternColor = WdColor.wdColorLightTurquoise;

Bt_Tech_Table.Rows[1].Cells[2].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[2].Shading.BackgroundPatternColor = WdColor.wdColorLightGreen;

Bt_Tech_Table.Rows[1].Cells[3].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[3].Shading.BackgroundPatternColor = WdColor.wdColorLightBlue;

Bt_Tech_Table.Rows[1].Cells[4].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[4].Shading.BackgroundPatternColor = WdColor.wdColorLavender;

Bt_Tech_Table.Rows[1].Cells[5].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[5].Shading.BackgroundPatternColor = WdColor.wdColorLightOrange;

Bt_Tech_Table.Rows[1].Cells[6].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[6].Shading.BackgroundPatternColor = WdColor.wdColorLightYellow;

Bt_Tech_Table.Rows[1].Cells[7].Range.Text += "x-content";
Bt_Tech_Table.Rows[1].Cells[7].Shading.BackgroundPatternColor = WdColor.wdColorGray35;

Bt_Tech_Table.Columns.AutoFit();

for ( int i =0; i< 4; i++)
{
    for (int j = 0; j < 7; j++)
    {
        cell.Range.Font.Bold = 0;
        Bt_Tech_Table.Rows[i+2].Cells[j+1].Range.Text += this.dgv_BT.Rows[i].Cells[j].Value.ToString();

        if ((i+2) == 5 || (j+1) == 7)
        {
            Bt_Tech_Table.Rows[i + 2].Cells[j + 1].Shading.BackgroundPatternColor = WdColor.wdColorGray35;
        }
    }
}

pIntroTable_BT.Range.InsertParagraphAfter();

Paragraph pMP_Text = document.Paragraphs.Add(cell.Range);
pMP_Text.Range.Font.Bold = 1;
pMP_Text.Range.Font.Size = 7;
pMP_Text.Range.Font.Underline = WdUnderline.wdUnderlinesingle;
pMP_Text.Range.Text = "x-content";
pMP_Text.Range.InsertParagraphAfter();

Paragraph pIntroTable_MP = document.Paragraphs.Add(cell.Range);
Table Bt_MP_Table = document.Tables.Add(pIntroTable_MP.Range,2,ref missing);
Bt_MP_Table.Borders.Enable = 1;
Bt_MP_Table.Range.Font.Underline = WdUnderline.wdUnderlineNone;
Bt_MP_Table.Range.Paragraphs.Alignment = WdParagraphAlignment.wdalignParagraphCenter;
Bt_MP_Table.AllowAutoFit = true;

Bt_MP_Table.Rows[1].Cells[1].Range.Text += "x-content";
Bt_MP_Table.Rows[1].Cells[1].Shading.BackgroundPatternColor = WdColor.wdColorLightTurquoise;

Bt_MP_Table.Rows[1].Cells[2].Range.Text += "x-content";
Bt_MP_Table.Rows[1].Cells[2].Shading.BackgroundPatternColor = WdColor.wdColorLightGreen;

Bt_MP_Table.Rows[1].Cells[3].Range.Text += "x-content";
Bt_MP_Table.Rows[1].Cells[3].Shading.BackgroundPatternColor = WdColor.wdColorLightBlue;

Bt_MP_Table.Rows[1].Cells[4].Range.Text += "x-content";
Bt_MP_Table.Rows[1].Cells[4].Shading.BackgroundPatternColor = WdColor.wdColorLavender;

Bt_MP_Table.Rows[1].Cells[5].Range.Text += "x-content";
Bt_MP_Table.Rows[1].Cells[5].Shading.BackgroundPatternColor = WdColor.wdColorLightOrange;

Bt_MP_Table.Columns.AutoFit();

for (int j = 0; j < 5; j++)
{
    Bt_MP_Table.Rows[2].Cells[j + 1].Range.Text += this.dgv_Crit.Rows[0].Cells[j].Value.ToString();
}
pIntroTable_MP.Range.InsertParagraphAfter();

我尝试了很多对范围的操作,添加了段落,试图理解一种方法来做到这一点。到目前为止,我按照自己的意愿成功放置它们的唯一合法方法添加不引用 cell.Range 的段落。

我知道表格完全“吃掉”了范围,这就是为什么我认为使用不同的段落会成功。

非常感谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。