Java程序打印excel文件

下载Jcom   jar包   http://sourceforge.net/projects/jcom/

把包里的jcom.jar放到classpath,把jcom.dll放到java_home/bin下面

 

测试:

package test;

import   jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
import   jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelApplication;
import   jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbook;
import   jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbooks;
import   jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet;

public   class   Jcom {

        public   boolean   print(String   fname) {
                ReleaseManager   rm   =   new   ReleaseManager();
                try  {
                        ExcelApplication   excel   =   new   ExcelApplication(rm);

                        ExcelWorkbooks   xlBooks   =   excel.Workbooks();
                        ExcelWorkbook   xlBook   =   xlBooks.Open(fname);
                        ExcelWorksheet   xlSheet   =   excel.ActiveSheet();

                        xlSheet.PrintOut();

                        xlBook.Close(false,   null,   false);
                        excel.Quit();
                }   catch   (Exception   e)  {
                        e.printStackTrace();
                        return   false;
                }   finally  {
                        rm.release();
                }
                return   true;
        }

        public   static   void   main(String[]   args) {
                Jcom   test   =   new   Jcom();

                try  {
                        test.print("c:/test.xls");
                }   catch   (Exception   e)  {
                        e.printStackTrace();
                }
        }
}

 

 

你可能感兴趣的:(java,打印,Excel)