日期:2014-05-17 浏览次数:20806 次
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:\\报表.xls");
} catch (Exception e) {
e.printStackTrace();
}
}
}
jp.ne.so_net.ga2.no_ji.jcom.JComException: IDispatch::Invoke(0x6EC,1) failed HRESULT=0x80020009L
at jp.ne.so_net.ga2.no_ji.jcom.IDispatch._invoke(Native Method)
at jp.ne.so_net.ga2.no_ji.jcom.IDispatch.method(IDispatch.java:223)
at jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet.PrintOut(ExcelWorksheet.java:138)
at com.bluestar.dbbx.pojo.JCOM.print(JCOM.java:20)
at com.bluestar.dbbx.pojo.JCOM.main(JCOM.java:37)