介绍

获取Aspose.Diagram for Java库的版本

getVersion() 方法由Diagram类和由公开的 getBuildNumberCreated() 方法文档属性类用于确定用于创建文档的 Microsoft Visio 实例的版本和完整构建号。

Determining the Version of Microsoft Visio 创建、编辑和保存文档

getBuildNumberEdited() 方法由文档属性类用于确定用于编辑文档的 Microsoft Visio 实例的完整构建号。

getTimeCreated()、getTimeEdited()、getTimePrinted() 和 getTimeSaved() 方法由文档属性class 用于确定 Microsoft Visio 文档的创建、最后编辑、最后打印和最后保存的时间。

您还可以设置这些属性来更改文件中的信息。

下面的代码示例显示了如何检索有关文件创建者以及文件创建、编辑、打印和保存时间的信息。

控制台窗口中的代码输出

待办事项:图片_替代_文本

编程范例

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetLibraryVersion.class);
// build path of an existing diagram
String path = dataDir + "Drawing1.vsdx";
//Call the diagram constructor to load diagram from a VDX file
Diagram diagram = new Diagram(path);
//Display Visio version and document modification time at different stages
System.out.println("Visio Instance Version : " + diagram.getVersion());
System.out.println("Full Build Number Created : " + diagram.getDocumentProps().getBuildNumberCreated());
System.out.println("Full Build Number Edited : " + diagram.getDocumentProps().getBuildNumberEdited());
System.out.println("Date Created : " + diagram.getDocumentProps().getTimeCreated());
System.out.println("Date Last Edited : " + diagram.getDocumentProps().getTimeEdited());
System.out.println("Date Last Printed : " + diagram.getDocumentProps().getTimePrinted());
System.out.println("Date Last Saved : " + diagram.getDocumentProps().getTimeSaved());

写作 Microsoft Visio 文档摘要信息

Microsoft Visio 允许您定义许多文档摘要信息属性,以帮助您和您的同事识别 diagram。摘要属性,例如标题、主题、作者和描述,使文件在搜索时更容易找到,在浏览时更容易识别文件。

文档属性类公开了一些属性来设置或获取 Microsoft Visio diagram 的摘要信息。 Aspose.Diagram for Java 可以更新图纸汇总信息,然后将图纸文件写回VDX。

写作 Microsoft Visio 文档摘要信息

要更新现有 VDX 或 VSD 文件的图纸摘要信息:

  1. 创建一个实例Diagram班级。
  2. 设置 Diagram.getDocumentProps() 方法公开的属性,以定义 Visio 绘图文件的摘要信息。
  3. 调用Diagram类的save()方法将Visio绘图文件写入VDX。

查看摘要信息:

  1. 在Microsoft Visio打开输出VDX文件。
  2. 选择信息来自文件菜单。

显示更新的摘要信息的信息对话框

待办事项:图片_替代_文本

编程范例

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SetVisioProperties.class);
// build path of an existing diagram
String path = dataDir + "Drawing1.vsdx";
//Call the diagram constructor to load diagram from a VSDX file
Diagram diagram = new Diagram(path);
//Set some summary information about the diagram
diagram.getDocumentProps().setCreator("Ijaz");
diagram.getDocumentProps().setCompany("Aspose");
diagram.getDocumentProps().setCategory("Drawing 2D");
diagram.getDocumentProps().setManager("Sergey Polshkov");
diagram.getDocumentProps().setTitle("Aspose Title");
diagram.getDocumentProps().setTimeCreated(DateTime.getNow());
diagram.getDocumentProps().setSubject("Visio Diagram");
diagram.getDocumentProps().setTemplate("Aspose Template");
//Write the updated file to the disk in VSDX file format
diagram.save(dataDir + "SetVisioProperties_Out.vsdx", SaveFileFormat.VSDX);

检测 Visio 文件的格式

使用Aspose.Diagram for JavaAPI,开发者可以在打开Visio文件前检测其格式,因为文件扩展名并不能保证文件内容是合适的。

检测格式编程示例

以下示例代码说明了如何检测文件格式(使用文件路径或流)并检查其扩展名。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectVisioFileFormat.class);
// detect file format using the direct file path
FileFormatInfo info = FileFormatUtil.detectFileFormat(dataDir + "Drawing1.vsdx");
// get the detected file format
System.out.println("The spreadsheet format is: " + info.getFileFormatType());

从 InputStream 检测 Visio 文件的格式

使用 Aspose.Diagram for Java API,开发人员可以通过传递输入流来检测 Visio 文件的格式。 FileFormatUtil 类的 detectFileFormat 方法可用于实现此目的。

从 InputStream 编程示例中检测格式

以下示例代码说明了如何使用输入流检测文件格式。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectFormatfromInputStream.class);
// Open the stream. Read only access to load a Visio diagram.
String stream = new String(dataDir + "Drawing1.vsdx");
// detect file format using an input stream
FileFormatInfo info = FileFormatUtil.detectFileFormat(stream);
// get the detected file format
System.out.println("The spreadsheet format is: " + info.getFileFormatType());