因為項目有個需求
首先想到的是java自帶的打印類
view plaincopy to clipboardprint?
/**
* @author xjj
* 說明:打印類
* email:
* @date Oct
*/
public class AutoPrint {
public static void main(String[] args) {
FileInputStream psStream;
try {
psStream = new FileInputStream(
} catch (FileNotFoundException ffne) {
}
if (psStream == null) {
return;
}
DocFlavor psInFormat = DocFlavor
Doc myDoc = new SimpleDoc(psStream
PrintRequestAttributeSet aset =
new HashPrintRequestAttributeSet();
aset
aset
aset
PrintService[] services =
PrintServiceLookup
if(services
throw new RuntimeException(
}
if (services
DocPrintJob job = services[
try {
job
} catch (PrintException pe) {}
}
}
/**
* @author xjj
* 說明:打印類
* email:
* @date Oct
*/
public class AutoPrint {
public static void main(String[] args) {
FileInputStream psStream;
try {
psStream = new FileInputStream(
} catch (FileNotFoundException ffne) {
}
if (psStream == null) {
return;
}
DocFlavor psInFormat = DocFlavor
Doc myDoc = new SimpleDoc(psStream
PrintRequestAttributeSet aset =
new HashPrintRequestAttributeSet();
aset
aset
aset
PrintService[] services =
PrintServiceLookup
if(services
throw new RuntimeException(
}
if (services
DocPrintJob job = services[
try {
job
} catch (PrintException pe) {}
}
}
通過測試
有道是
充當java和windows平台的橋梁作用
閒話少說
進入官網
解壓:jacob
ok
view plaincopy to clipboardprint?
/**
* 功能:實現打印工作
* @param path
* @date Oct
* @time
*/
public static void print(String path){
ComThread
ActiveXComponent xl = new ActiveXComponent(
try {
// System
//不打開文檔
Dispatch
Dispatch workbooks = xl
//打開文檔
Dispatch excel=Dispatch
//開始打印
Dispatch
} catch (Exception e) {
e
} finally {
//始終釋放資源
ComThread
}
}
/**
* 功能:實現打印工作
* @param path
* @date Oct
* @time
*/
public static void print(String path){
ComThread
ActiveXComponent xl = new ActiveXComponent(
try {
// System
//不打開文檔
Dispatch
Dispatch workbooks = xl
//打開文檔
Dispatch excel=Dispatch
//開始打印
Dispatch
} catch (Exception e) {
e
} finally {
//始終釋放資源
ComThread
}
}
然後
說個題外話
根據我所掌握的情況
x?familyid=
最後說一下
Java代碼
Exception in thread
at java
at java
at java
at
at com
at com
Java代碼
Exception in thread
iled to start because the application configuration is incorrect
oblem
Java代碼
Source: Microsoft Office Excel
Java代碼
cant get Object cldid from progid
好了
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25631.html