将形状插入到工作表中 Aspose.Cells

excel中的形状主要分为以下几种:

  • 线条
  • 矩形
  • 基本形状
  • 块箭头
  • 方程形状
  • 流程图
  • 星星和横幅
  • 标注

本指南文档将从每种类型中选择一个或两个形状来制作示例。通过这些示例,您将学习如何使用Aspose.Cells将指定的形状插入到工作表中。

在工作表中插入一行

线条的形状属于线条类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入行的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从“最近使用的形状”或“线条”中选择线条

使用 Aspose.Cells

您可以使用以下方法在工作表中插入一行。

以下示例显示如何向工作表插入行。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the line to the worksheet
sheet.getShapes().addShape(MsoDrawingType.LINE, 2, 0, 2, 0, 100, 300);//method 1
//sheet.getShapes().addAutoShape(AutoShapeType.LINE, 2, 0, 2, 0, 100, 300);//method 2
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

向工作表插入线箭头

线箭头的形状属于线条category.It 是 line 的特例。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入直线箭头的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从“最近使用的形状”或“线条”中选择线条箭头

使用 Aspose.Cells

您可以使用以下方法在工作表中插入线箭头。

以下示例显示如何将线箭头插入工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the line arrow to the worksheet
Shape s = sheet.getShapes().addShape(MsoDrawingType.LINE, 2, 0, 2, 0, 100, 300);//method 1
//Shape s = sheet.getShapes().addAutoShape(AutoShapeType.LINE, 2, 0, 2, 0, 100, 300);//method 2
//add a arrow at the line begin
s.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
s.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.WIDE);//arrow width
s.getLine().setBeginArrowheadLength(MsoArrowheadLength.SHORT);//arrow length
//add a arrow at the line end
s.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW_OPEN);//arrow type
s.getLine().setEndArrowheadWidth(MsoArrowheadWidth.NARROW);//arrow width
s.getLine().setEndArrowheadLength(MsoArrowheadLength.LONG);//arrow length
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

在工作表中插入一个矩形

矩形的形状属于矩形类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入矩形的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从“最近使用的形状”或“矩形”中选择矩形

使用 Aspose.Cells

您可以使用以下方法在工作表中插入一个矩形。

以下示例显示如何将矩形插入到工作表中。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the rectangle to the worksheet
ShapeCollection shapes = sheet.getShapes();
shapes.addShape(MsoDrawingType.RECTANGLE, 2, 0, 2, 0, 100, 300);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

将多维数据集插入工作表

立方体的形状属于基本形状类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入立方体的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择多维数据集基本形状

使用 Aspose.Cells

您可以使用以下方法在工作表中插入一个立方体。

以下示例显示如何将多维数据集插入工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the cube to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.CUBE, 2, 0, 2, 0, 100, 300);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

将标注四箭头插入工作表

标注四箭头的形状属于块箭头类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入标注四箭头的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择标注四箭头块箭头

使用 Aspose.Cells

您可以使用以下方法在工作表中插入标注四箭头。

以下示例显示如何将标注四箭头插入工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the callout quad arrow to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.QUAD_ARROW_CALLOUT, 2, 0, 2, 0, 100, 100);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

在工作表中插入乘号

乘号的形状属于方程形状类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入乘号的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择乘号方程形状

使用 Aspose.Cells

您可以使用以下方法在工作表中插入乘号。

以下示例显示如何将乘号插入工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the multiplication sign to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.MATH_MULTIPLY, 2, 0, 2, 0, 100, 100);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

将多文档插入工作表

多文档的形状属于流程图类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入多文档的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择多文档流程图

使用 Aspose.Cells

您可以使用以下方法在工作表中插入多文档。

以下示例显示如何将多文档插入到工作表中。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the multidocument to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.FLOW_CHART_MULTIDOCUMENT, 2, 0, 2, 0, 100, 100);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

在工作表中插入一个五角星

五角星的形状属于星星和横幅类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入五角星的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择五角星星星和横幅

使用 Aspose.Cells

您可以使用以下方法在工作表中插入一个五角星。

以下示例显示如何将五角星插入工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the Five-pointed star to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.STAR_5, 2, 0, 2, 0, 100, 100);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果:

将思想气泡云插入工作表

思想气泡云的形状属于标注类别。

在 Microsoft Excel 中(例如 2007):

  • 选择要插入思想气泡云的单元格
  • 单击插入菜单,然后单击形状。
  • 然后,从中选择思想气泡云标注

使用 Aspose.Cells

您可以使用以下方法在工作表中插入思想泡泡云。

以下示例显示如何将思想泡泡云插入到工作表中。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the thought bubble cloud to the worksheet
sheet.getShapes().addAutoShape(AutoShapeType.CLOUD_CALLOUT, 2, 0, 2, 0, 100, 100);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

执行上面的代码,你会得到如下结果: