Infragistics Excelライブラリでは、WorksheetShape.createPredefinedShape()メソッドを使用して以下の事前定義された図形を新規作成することができます。
| 形式 | PredefinedShapeType |
| 線 | Line |
| ひし形 | Diamond |
| 楕円 | Ellipse |
| ハート | Heart |
| 爆発 1 | IrregularSeal1 |
| 爆発 2 | IrregularSeal2 |
| 五角形 | Pentagon |
| 正方形/長方形 | Rectangle |
| 直角三角形 | RightTriangle |
| 稲妻 | LightningBolt |
//新規のWorkbookを作成します。
const workbook = new Workbook(WorkbookFormat.Excel2007);
//Worksheetを追加します。
const sheet = workbook.worksheets().add('Sheet1');
// WorksheetShape.createPredefinedShapeメソッドを使用してRectangleのShapeを作成します。
const shape = WorksheetShape.createPredefinedShape(PredefinedShapeType.Rectangle);
//fillプロパティで塗りつぶしの色を設定します。
shape.fill = ShapeFill.fromColor("SteelBlue");
//outlineプロパティで線の色を設定します。
shape.outline = ShapeOutline.fromColor("Red");
//Shapeを配置するセルと位置をtopLeftCornerCell、topLeftCornerPosition、bottomRightCornerCell、bottomRightCornerPositionプロパティで指定します。
shape.topLeftCornerCell = sheet.rows(2).cells(2);
shape.topLeftCornerPosition = { x: 50, y: 100 };
shape.bottomRightCornerCell = sheet.rows(10).cells(5);
shape.bottomRightCornerPosition = { x: 50, y: 100 };
//テキストを追加する場合は、ShapeをRectangleShapeにキャストしてから、textプロパティにFormattedTextを設定します。
const ft = new FormattedText("infragistics");
(shape as RectangleShape).text = ft;
ft.getFont(0, 12).bold = true;
const color = new Color();
color.colorString = "Yellow";
ft.getFont(0, 12).colorInfo = new WorkbookColorInfo(color);
ft.getFont(0, 1).height = 1000;
ft.getFont(5, 1).height = 1000;
//最後に、WorksheetのshapesコレクションにShapeを追加します。
sheet.shapes().add(shape);
