// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["B1"].Value = "テキスト全体の配置を設定"; worksheet.Range["G1"].Value = "各段落の配置を設定"; IShape shapeOfLeftTopAlignment = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B3:E6"]); shapeOfLeftTopAlignment.TextFrame.TextRange.Add("1番目の図形"); shapeOfLeftTopAlignment.TextFrame.TextRange.Add("左上揃えの配置"); // 1番目の図形のテキスト配置を左上揃えに設定 shapeOfLeftTopAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Left; shapeOfLeftTopAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorTop; IShape shapeOfCenterMiddleAlignment = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B8:E11"]); shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("2番目の図形"); shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("中央揃えの配置"); // 2番目の図形のテキスト配置を中央揃えに設定 shapeOfCenterMiddleAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Center; shapeOfCenterMiddleAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle; IShape shapeOfRightBottomAlignment = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B13:E16"]); shapeOfRightBottomAlignment.TextFrame.TextRange.Add("3番目の図形"); shapeOfRightBottomAlignment.TextFrame.TextRange.Add("右下揃えの配置"); // 3番目の図形のテキスト配置を右下揃えに設定 shapeOfRightBottomAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Right; shapeOfRightBottomAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorBottom; IShape shapeOfThereAlignmentParagraphs = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["G3:J6"]); shapeOfThereAlignmentParagraphs.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle; // 最後の図形にて、3つの段落に異なる配置を設定 shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("左揃え"); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("中央揃え"); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("右揃え"); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[0].TextAlignment = TextAlignmentAnchor.Left; shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[1].TextAlignment = TextAlignmentAnchor.Center; shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[2].TextAlignment = TextAlignmentAnchor.Right; // xlsx ファイルに保存 workbook.Save("SetShapeTextAlignment.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("B1").Value = "テキスト全体の配置を設定" worksheet.Range("G1").Value = "各段落の配置を設定" Dim shapeOfLeftTopAlignment As IShape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B3:E6")) shapeOfLeftTopAlignment.TextFrame.TextRange.Add("1番目の図形") shapeOfLeftTopAlignment.TextFrame.TextRange.Add("左上揃えの配置") ' 1番目の図形のテキスト配置を左上揃えに設定 shapeOfLeftTopAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Left shapeOfLeftTopAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorTop Dim shapeOfCenterMiddleAlignment As IShape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B8:E11")) shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("2番目の図形") shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("中央揃えの配置") ' 2番目の図形のテキスト配置を中央揃えに設定 shapeOfCenterMiddleAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Center shapeOfCenterMiddleAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle Dim shapeOfRightBottomAlignment As IShape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B13:E16")) shapeOfRightBottomAlignment.TextFrame.TextRange.Add("3番目の図形") shapeOfRightBottomAlignment.TextFrame.TextRange.Add("右下揃えの配置") ' 3番目の図形のテキスト配置を右下揃えに設定 shapeOfRightBottomAlignment.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Right shapeOfRightBottomAlignment.TextFrame.VerticalAnchor = VerticalAnchor.AnchorBottom Dim shapeOfThereAlignmentParagraphs As IShape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("G3:J6")) shapeOfThereAlignmentParagraphs.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle ' 最後の図形にて、3つの段落に異なる配置を設定 shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("左揃え") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("中央揃え") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("右揃え") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(0).TextAlignment = TextAlignmentAnchor.Left shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(1).TextAlignment = TextAlignmentAnchor.Center shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(2).TextAlignment = TextAlignmentAnchor.Right ' xlsx ファイルに保存 workbook.Save("SetShapeTextAlignment.xlsx")