请问,如何在单词标题表中插入指定单元格? 以下代码不起作用,这两个形状只能在第一个单元格中。
Range oCell1 = newTable.Cell(1, 1).Range;
float top1 = oWord.Selection.get_Information(WdInformation.wdVerticalPositionRelativeToPage);
float left1 = oWord.Selection.get_Information(WdInformation.wdHorizontalPositionRelativeToPage);
newTable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalBottom;
newTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
Microsoft.Office.Interop.Word.Shape shape1 = oDoc.Shapes.AddShape(shapeId, left1, top1 , oWord.CentimetersToPoints(float.Parse("1.1")), oWord.CentimetersToPoints(float.Parse("0.5")), oCell1);
Range oCell2 = newTable.Cell(1, 3).Range;
float top2 = oWord.Selection.get_Information(WdInformation.wdVerticalPositionRelativeToPage);
float left2 = oWord.Selection.get_Information(WdInformation.wdHorizontalPositionRelativeToPage);
Microsoft.Office.Interop.Word.Shape shape2 = oDoc.Shapes.AddShape(shapeId, left2, top2 , oWord.CentimetersToPoints(float.Parse("1.1")), oWord.CentimetersToPoints(float.Parse("0.5")), oCell2);
答案 0 :(得分:0)
Word有时不会恰当地放置东西。你可以绕过它的一种方法是将它放在别处,然后复制/粘贴到所需的位置。
Selection sel = doc.Application.Selection;
Table newTable = sel.Tables[1];
Cell cell_1 = newTable.Cell(1, 1);
Range oCell1 = cell_1.Range;
float top1 = sel.get_Information(WdInformation.wdVerticalPositionRelativeToPage);
float left1 = sel.get_Information(WdInformation.wdHorizontalPositionRelativeToPage);
cell_1.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalBottom;
cell_1.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
Interop.Shape shape1 = doc.Shapes.AddShape((int)MsoAutoShapeType.msoShapeCube,
left1, top1, app.CentimetersToPoints(float.Parse("1.1")),
app.CentimetersToPoints(float.Parse("0.5")), oCell1);
shape1.ConvertToInlineShape();
oCell1.Copy();
Range oCell2 = newTable.Cell(1, 3).Range;
oCell2.Select();
oCell2.Paste();