Java程序打印excel文件
2008-01-15 23:00
309 查看
具体是这样的,去下载一个叫jcom的lib,是日本人做的,整个包里注释全是日文。
把包里的jcom.jar放到classpath,把jcom.dll放到java_home/bin下面
然后写个程序
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package raito.print;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelApplication;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbook;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbooks;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class JCOM ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public boolean print(String fname) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ReleaseManager rm = new ReleaseManager();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelApplication excel = new ExcelApplication(rm);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorkbooks xlBooks = excel.Workbooks();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorkbook xlBook = xlBooks.Open(fname);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorksheet xlSheet = excel.ActiveSheet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xlSheet.PrintOut();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xlBook.Close(false, null, false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
excel.Quit();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} finally ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
rm.release();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
JCOM test = new JCOM();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
test.print("c:/test.xls");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
jcom.jar 下载:http://downloads.sourceforge.net/jcom/jcom224.zip?modtime=1087776000&big_mirror=0
把包里的jcom.jar放到classpath,把jcom.dll放到java_home/bin下面
然后写个程序
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package raito.print;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelApplication;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbook;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbooks;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class JCOM ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public boolean print(String fname) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ReleaseManager rm = new ReleaseManager();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelApplication excel = new ExcelApplication(rm);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorkbooks xlBooks = excel.Workbooks();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorkbook xlBook = xlBooks.Open(fname);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ExcelWorksheet xlSheet = excel.ActiveSheet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xlSheet.PrintOut();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xlBook.Close(false, null, false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
excel.Quit();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} finally ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
rm.release();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
JCOM test = new JCOM();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
test.print("c:/test.xls");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
jcom.jar 下载:http://downloads.sourceforge.net/jcom/jcom224.zip?modtime=1087776000&big_mirror=0
相关文章推荐
- Java程序如何打印excel文件
- 第4章 流程控制----编写Java程序,应用for循环打印菱形
- 用浏览器打开Excel文件的Java程序
- Java小程序之用*打印正/倒立三角形
- java程序打印输出本月日历
- java程序运行打印的时间与系统时间不符慢8小时的解决方法
- Java 编程思想 写一个程序,打印出从命令行获取的三个自变量。
- Java程序打印奥林匹克标志方法详解
- Android JNI编程(八)——体验AS2.2.2编写Jni程序、Java调C、C调Java函数、将C代码中的Log打印至Logcat
- 在Java程序中实现高精度打印
- java打印程序——打印图片(不带对话框)
- Java打印Excel文件 Jacob打印Excel文件
- 在Java程序中实现高精度打印
- 一个java小程序(打印出目录)
- java实现只接收数字输入,输入exit退出程序,并打印输入的数字
- java打印服务程序实现
- 用java写的打印日历小程序
- 使用Java程序控制Barone(Zebra)进行打印的代码
- Java小程序:打印空心菱形
- 03.JAVA 小程序—for循环打印菱形