有人用过吗?poi,jxl能有这个功能吗就是打开excel,另存为htm文件的功能

解决方案 »

  1.   

    jacob可以实现,我已经测试过没问题。
    class execl{
        public execl() {
        }    public static String file = "c:\\11.xls";    public static String tpFile = "c:\\12.txt"; //临时文件
        public static String otFile = "c:\\my.doc"; //目标文件
        public void execlToTxt(String execlFile, String txtFile) {
            ActiveXComponent app = new ActiveXComponent("excel.Application"); //启动execl        app.setProperty("Visible", new Variant(false)); //设置execl不可见        Object docs = app.getProperty("Workbooks").toDispatch();        Object doc = Dispatch.invoke(docs, "Open", Dispatch.Method,
                                         new Object[] {execlFile, new Variant(false),
                                         new Variant(true)}, new int[1]).toDispatch(); //打开execl文件
            Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {txtFile,
                            new Variant(3)}, new int[1]); //另存为txt文件        
            app.invoke("Quit", new Variant[] {});    }    public static void main(String[] args) {
            try {            execl Excel = new execl();
                Excel.execlToTxt("c:\\12.xls", "c:\\12.txt");
                //  Thread.sleep(10000);
                //System.out.println("wait 10s");
                //Excel.TxtToPdf("c:\\12.txt", "c:\\12.pdf");        } catch (Exception e) {
                System.out.println(e.getMessage());
            }    }这个例子是转为.txt文件的,你只要将这句代码Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {txtFile,
                            new Variant(3)}, new int[1]); //作为html格式保存到临时文件  
    中的new int[1]参数中的1改一下就行了,具体改多少我忘了。只要是EXCEL中另存为功能中能给出的文件类型都能直接用这个方法实现,你测试一下吧。有问题再联系我。
      

  2.   

    jacob的包去网上搜一下,找得到地方下载,另外还有一定的配置要求,有点烦,你设置一下就行了。
    我的配置:jdk1.3.1_16 + jacob.jar 1.7 + jacob.dll的jacob_jre142fix_bin版本(104KB)