鍍金池/ 問(wèn)答/C#  網(wǎng)絡(luò)安全/ c# word中插入形狀到固定的table單元格

c# word中插入形狀到固定的table單元格

請(qǐng)問(wèn),如何在word頁(yè)眉的table中插入形狀到指定的cell中?
下面代碼沒(méi)有效果,兩個(gè)形狀只能在第一個(gè)單元格中。

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);

clipboard.png

回答
編輯回答
怣痛

最后選擇通過(guò)計(jì)算方式來(lái)實(shí)現(xiàn)。

2017年5月9日 11:04