使用 Java 创建 Visio 图表

本文涵盖了使用 Java 创建 Visio 图表的信息。它讨论了使用 Java 自动创建 Visio 图表的分步程序流程和运行代码片段。此外,您还可以使用多种 Visio 支持的文件格式编写生成的 Visio 图表。

使用 Java 创建 Visio 图表的步骤

  1. 配置 Aspose.Diagram 库以从头开始制作 Visio 图表
  2. 启动 Diagram 类的对象
  3. 使用模板文件添加母版
  4. 通过调用 addShape() 方法添加矩形并指定各种属性
  5. 使用 save() 方法呈现生成的 Visio 图表

这些步骤概述了如何在 Java 中创建 Visio。首先,制作一个空图表并启动包含主形状的模板。接下来,在导出输出 Visio 图表之前,附加一个形状,同时设置位置、尺寸和目标页码。

使用 Java 以编程方式创建 Visio 图表的代码

// Import the required classes from Aspose.Drawing for Java
import com.aspose.diagram.*;
public class Main
{
public static void main(String[] args) throws Exception {
// Apply the license for Aspose.PDF
new License().setLicense("license.lic");
// Create a diagram
com.aspose.diagram.Diagram diagram = new com.aspose.diagram.Diagram();
// Add master with stencil
String masterName = "Rectangle";
diagram.addMaster("BasicShapes.vss", masterName);
double width = 2, height = 2, pinX = 4.25, pinY = 4.5;
// Add a new rectangle shape
long rectangleId = diagram.addShape(pinX, pinY, width, height, masterName, 0);
// Set shape properties
com.aspose.diagram.Shape rectangle = diagram.getPages().get(0).getShapes().getShape(rectangleId);
rectangle.getXForm().getPinX().setValue(5);
rectangle.getXForm().getPinY().setValue(5);
rectangle.setType(com.aspose.diagram.TypeValue.SHAPE);
rectangle.getText().getValue().add(new com.aspose.diagram.Txt("Aspose Diagram"));
rectangle.setTextStyle(diagram.getStyleSheets().get(3));
diagram.save("Visio_out.vsdx", com.aspose.diagram.SaveFileFormat.VSDX);
}
}

您可以使用上述示例代码绘制任何Java 版 Visio 中的流程图。但是,您可以即兴发挥,从主模板中添加不同的形状以满足您的要求。同样,输出的 Visio 图表可以导出为图像或文档,具体取决于您的需要。

这篇简短的文章总结了使用 Java 以编程方式创建 Visio 图表的细节。然而,如果您想了解如何转换 VSD 文件,请参阅 使用 Java 将 VSD 转换为 VSDX 上的文章。

 简体中文