【发布时间】:2016-11-08 02:06:47
【问题描述】:
我正在尝试将 Microsoft.Office.Interop.Word.Shape 放在一个表格单元格中,就像这个简短的示例一样:
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), 4, 1);
Word.Cell oCell1 = oTable.Cell(1,1);
Word.Shape oShape1 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell1.Range);
Word.Cell oCell2 = oTable.Cell(2, 1);
Word.Shape oShape2 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell2.Range);
Word.Cell oCell3 = oTable.Cell(3, 1);
Word.Shape oShape3 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell3.Range);
Word.Cell oCell4 = oTable.Cell(4, 1);
Word.Shape oShape4 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell4.Range);
oWord.Visible = true;
矩形只出现在文档的左上角。 我不确定自己做错了什么,因为我将形状锚点设置为单元格范围。
2016 年 12 月 7 日:
好的,看看这个, 我现在有 5 列和 100 行,并尝试将形状放入第三列。我正在使用“符合文本”属性。
现在,在前两页上,所有形状都放在第一行/第一列。从第三页开始,它看起来不错...
我使用的是 Office 2013。
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
int numRows = 100;
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), numRows, 5);
oTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
oTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
for (int r = 1; r <= numRows; ++r)
{
Word.Range anchorRange = oTable.Cell(r, 3).Range;
Word.Shape oShape = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, anchorRange);
oShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapInline;
}
oWord.Visible = true;
【问题讨论】: