2017-11-07 6 views
0

실례합니다. 단어 표의 표 모양을 지정된 셀에 삽입하는 방법은 무엇입니까? 다음 코드는 작동하지 않습니다. 두 모양은 첫 번째 셀에서만 사용할 수 있습니다.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

말씀은 때때로 적절하게 물건을 올려 놓지 않습니다. 주위를 둘러 볼 수있는 한 가지 방법은 다른 위치로 이동 한 다음 원하는 위치에 복사/붙여 넣기하는 것입니다.

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