Microsoft & reg; Visio Tách tệp qua Java

Chia tài liệu Visio đơn lẻ thành các tệp khác nhau bằng cách sử dụng mã Java trong các ứng dụng dựa trên Java

 

Java Visio Thư viện có khả năng chia tài liệu Visio thành nhiều trang trong các ứng dụng dựa trên Java. Các định dạng tệp được hỗ trợ bao gồm VDW, VDX, VSD, VSDM, VSDX, VSS, VSSM, VSSX, VST, VSTM, VSTX, VSX, VTX.

Tách tài liệu Visio thành nhiều tệp

Cách đơn giản nhất để chia Visio trang tệp một cách khôn ngoan là Truy cập tất cả các trang qua trang Lặp lại từng trang và gọi Sao chép phương pháp. Cuối cùng lưu nó vào một đường dẫn được chỉ định.

  • Tải tệp Visio với đường dẫn đầy đủ bằng cách sử dụng diagram lớp . Lặp lại từng trang
  • Tạo một đối tượng lớp Diagram mới
  • Sao chép trang qua Sao chép phương pháp
  • Gọi phương thức save () và truyền vào tên tệp (đường dẫn đầy đủ) có SaveFormat phù hợp.
Java Mã để Tách Visio Tệp
// 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(CopyVisioPage.class);
// Call the diagram constructor to load diagram from a VSD file
Diagram originalDiagram = new Diagram(dataDir + "Drawing1.vsd");
// initialize the new visio diagram
Diagram newDiagram = new Diagram();
// add all masters from the source Visio diagram
MasterCollection originalMasters = originalDiagram.getMasters();
for (Master master : (Iterable<Master>) originalMasters) {
newDiagram.addMaster(originalDiagram, master.getName());
}
// get the page object from the original diagram
Page SrcPage = originalDiagram.getPages().getPage("Page-1");
// set page name
SrcPage.setName("new page");
// it calculates max page id
int max = 0;
if (newDiagram.getPages().getCount() != 0)
max = newDiagram.getPages().get(0).getID();
for (int i = 1; i < newDiagram.getPages().getCount(); i++)
{
if (max < newDiagram.getPages().get(i).getID())
max = newDiagram.getPages().get(i).getID();
}
int MaxPageId = max;
// set page id
SrcPage.setID(MaxPageId);
// add reference of the original diagram page
newDiagram.getPages().add(SrcPage);
// remove first empty page
newDiagram.getPages().remove(newDiagram.getPages().get(0));
// save diagram in VDX format
newDiagram.save(dataDir + "CopyVisioPage_Out.vsdx", SaveFileFormat.VSDX);