// Create a new workbook Workbook workbook = new Workbook(); InputStream fileStream = this.getResourceStream("xlsx\\TemplateWorkWithChart.xlsx"); workbook.open(fileStream, OpenFileFormat.Xlsx); IWorksheet worksheet = workbook.getWorksheets().get(0); IShape shape1 = worksheet.getShapes().addShape(AutoShapeType.RoundedRectangle, (double)10, (double)10, (double)320, (double)150); shape1.getTextFrame().getTextRange().setTextAlignment(TextAlignmentAnchor.Left); shape1.getTextFrame().getTextRange().getFont().setName("Calibri"); shape1.getTextFrame().getTextRange().getFont().setSize(16); shape1.getTextFrame().getTextRange().getFont().getColor().setRGB(Color.GetBlack()); shape1.getTextFrame().getTextRange().getFont().setUnderline(TextUnderlineType.None); shape1.getTextFrame().getTextRange().getParagraphs().add("Quarterly Results"); shape1.getTextFrame().getTextRange().getParagraphs().get(0).setTextAlignment(TextAlignmentAnchor.Center); shape1.getTextFrame().getTextRange().getParagraphs().get(0).getFont().setSize(28); shape1.getTextFrame().getTextRange().getParagraphs().get(0).getFont().setUnderline(TextUnderlineType.Single); shape1.getTextFrame().getTextRange().getParagraphs().add(""); shape1.getTextFrame().getTextRange().getParagraphs().add("Business Domain: E-Commerce"); shape1.getTextFrame().getTextRange().getParagraphs().get(2).setTextAlignment(TextAlignmentAnchor.Left); shape1.getTextFrame().getTextRange().getParagraphs().add("Quarter: Q4"); shape1.getTextFrame().getTextRange().getParagraphs().get(3).setTextAlignment(TextAlignmentAnchor.Left); shape1.getLine().setDashStyle(LineDashStyle.Solid); shape1.getLine().setStyle(LineStyle.Single); shape1.getLine().getColor().setRGB(Color.GetBlack()); shape1.getFill().getColor().setRGB(Color.FromArgb(242, 242, 242)); // Save to an excel file workbook.save("UseCaseOfShapeTextAlignment.xlsx");
// Create a new workbook var workbook = Workbook() val fileStream = getResourceStream("xlsx\\TemplateWorkWithChart.xlsx") workbook.open(fileStream, OpenFileFormat.Xlsx) val worksheet = workbook.worksheets[0] val shape1 = worksheet.shapes.addShape(AutoShapeType.RoundedRectangle, 10.0, 10.0, 320.0, 150.0) shape1.textFrame.textRange.textAlignment = TextAlignmentAnchor.Left shape1.textFrame.textRange.font.name = "Calibri" shape1.textFrame.textRange.font.size = 16.0 shape1.textFrame.textRange.font.color.rgb = Color.GetBlack() shape1.textFrame.textRange.font.underline = TextUnderlineType.None shape1.textFrame.textRange.paragraphs.add("Quarterly Results") shape1.textFrame.textRange.paragraphs[0].textAlignment = TextAlignmentAnchor.Center shape1.textFrame.textRange.paragraphs[0].font.size = 28.0 shape1.textFrame.textRange.paragraphs[0].font.underline = TextUnderlineType.Single shape1.textFrame.textRange.paragraphs.add("") shape1.textFrame.textRange.paragraphs.add("Business Domain: E-Commerce") shape1.textFrame.textRange.paragraphs[2].textAlignment = TextAlignmentAnchor.Left shape1.textFrame.textRange.paragraphs.add("Quarter: Q4") shape1.textFrame.textRange.paragraphs[3].textAlignment = TextAlignmentAnchor.Left shape1.line.dashStyle = LineDashStyle.Solid shape1.line.style = LineStyle.Single shape1.line.color.rgb = Color.GetBlack() shape1.fill.color.rgb = Color.FromArgb(242, 242, 242) // Save to an excel file workbook.save("UseCaseOfShapeTextAlignment.xlsx")