2017-11-07 5 views
0

すみません、指定されたセルに単語のヘッダーテーブルのシェイプを挿入する方法はありますか? 次のコードは機能しません。2つの図形は最初のセルにしか配置できません。C#指定されたセルにテーブルにシェイプを挿入する単語

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

enter image description here

答えて

0

言葉は時々、適切なものを置いていません。あなたが周りを回ることができる1つの方法は、それを別の場所に作ってから、目的の場所にコピー/貼り付けることです。

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(); 
関連する問題