//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["B1"].Value = "Config TextRange alignment"; worksheet.Range["G1"].Value = "Config each paragraph's alignment"; IShape shapeOfLeftTopAlignment = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B3:E6"]); shapeOfLeftTopAlignment.TextFrame.TextRange.Add("First shape."); shapeOfLeftTopAlignment.TextFrame.TextRange.Add("Left and top alignment."); // set first shape text alignment to left and top 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("Second shape."); shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("Center and middle alignment."); // set second shape text alignment to center and middle 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("Third shape."); shapeOfRightBottomAlignment.TextFrame.TextRange.Add("Right and bottom alignment."); // set third shape text alignment to right and bottom 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; // set different alignments for the three paragraphs of the last shape shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Left."); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Center."); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Right."); shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[0].TextAlignment = TextAlignmentAnchor.Left; shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[1].TextAlignment = TextAlignmentAnchor.Center; shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs[2].TextAlignment = TextAlignmentAnchor.Right; // Save to an excel file workbook.Save("SetShapeTextAlignment.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("B1").Value = "Config TextRange alignment" worksheet.Range("G1").Value = "Config each paragraph's alignment" Dim shapeOfLeftTopAlignment As IShape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B3:E6")) shapeOfLeftTopAlignment.TextFrame.TextRange.Add("First shape.") shapeOfLeftTopAlignment.TextFrame.TextRange.Add("Left and top alignment.") ' set first shape text alignment to left and top 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("Second shape.") shapeOfCenterMiddleAlignment.TextFrame.TextRange.Add("Center and middle alignment.") ' set second shape text alignment to center and middle 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("Third shape.") shapeOfRightBottomAlignment.TextFrame.TextRange.Add("Right and bottom alignment.") ' set third shape text alignment to right and bottom 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 ' set different alignments for the three paragraphs of the last shape shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Left.") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Center.") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Add("Right.") shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(0).TextAlignment = TextAlignmentAnchor.Left shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(1).TextAlignment = TextAlignmentAnchor.Center shapeOfThereAlignmentParagraphs.TextFrame.TextRange.Paragraphs(2).TextAlignment = TextAlignmentAnchor.Right ' save to an excel file workbook.Save("SetShapeTextAlignment.xlsx")