// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 1, 10, 250, 200); IShape shape2 = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 300, 10, 250, 200); //set the margin of text shape.getTextFrame().setMarginBottom(40); shape.getTextFrame().setMarginTop(40); shape.getTextFrame().setMarginRight(40); shape.getTextFrame().setMarginLeft(40); shape.getTextFrame().getTextRange().getParagraphs().get(0).getRuns().add("Test setting margin for text in a shape"); shape2.getTextFrame().getTextRange().getParagraphs().get(0).getRuns().add("Test input text with default margin"); // Save to an excel file workbook.save("SetMarginOfShapeText.xlsx");