Java 操作visio

本文介绍如何使用Java进行Visio文档的自动化操作,包括文档的打开、页面的定位及打印等功能。通过调用ActiveX组件实现对Visio应用程序的控制,并详细展示了设置文档可见性、获取活动文档及页面等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

int visCmdFilePrint = 1010;       
try {
            return Dispatch.call(oActiveX, "DoCmd", visCmdFilePrint).toInt();
boolean tVisible = true;
        ActiveXComponent visio = new ActiveXComponent("Visio.Application");
        visio.setProperty("Visible", new Variant(tVisible));
        Object documents = Dispatch.get(visio, "Documents").toDispatch();
        Object addon = Dispatch.get(visio, "Addons").toDispatch();
        Object orgWizAddon = Dispatch.call((Dispatch)addon, "ItemU", new Variant("OrgCWiz")).toDispatch();
        Object  activeDoc;
int pge = 1; //Specifies the document page to be displayed before saving document
            /*Move the current document to the first page before saving. This is done to ensure that this page is
             * always the first one displayed when the document is opened.*/
            activeDoc = Dispatch.get(visio, "ActiveDocument").toDispatch();
            Object activeDocPage = Dispatch.get((Dispatch)activeDoc, "Pages").toDispatch();           
            //Get the first page as a page object       
            Object gotoPage = Dispatch.invokev((Dispatch)activeDocPage, "Item", pge, new Variant [] {new Variant(pge)}, new int[1]).toDispatch();
            //Display the page name - just for debug purposes really
            Variant activePageName = Dispatch.get((Dispatch)gotoPage, "Name");
            System.out.println("Active page name is " + activePageName);
            //Get the active window (I don't know why, but this is how its done with VBA
            Object wnDow = Dispatch.get(visio, "ActiveWindow").toDispatch();
            //Move to the first page
            Dispatch.put((Dispatch)wnDow, "Page", gotoPage);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值