java的excel那个雷库能实现excel文件另存为htm的功能 有人用过吗?poi,jxl能有这个功能吗就是打开excel,另存为htm文件的功能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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中另存为功能中能给出的文件类型都能直接用这个方法实现,你测试一下吧。有问题再联系我。 jacob的包去网上搜一下,找得到地方下载,另外还有一定的配置要求,有点烦,你设置一下就行了。我的配置:jdk1.3.1_16 + jacob.jar 1.7 + jacob.dll的jacob_jre142fix_bin版本(104KB) eclipse语言包下载地址是多少(找不到)? 关于main(String args[]) 求一个简单的字附串替换问题,在线等 求解高手。 build.xml jar 打包 , 将byte[]转成int和C中atoi效果不一样 string查找符号字符? 就是查找内容用unicode表示? 大侠,在HTML中碰到",',<,>等,该怎样处理? 我的together很多功能、属性不能修改,为什么? 谁有UltraEdit9的注册码? 又一个困惑我的问题,呵呵 thinking in java(中文)第93页 怎样把一张jpeg图片显示在JinterFrame上面的一个Panel上?重金相谢
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中另存为功能中能给出的文件类型都能直接用这个方法实现,你测试一下吧。有问题再联系我。
我的配置:jdk1.3.1_16 + jacob.jar 1.7 + jacob.dll的jacob_jre142fix_bin版本(104KB)