java怎么打开excel文件呀 .例如:c:\demo.xls java怎么打开excel文件呀 .例如:c:\demo.xls 一定要用 Runtime run = Runtime.getRuntime();吗? 有没有其他的办法?能用jexcelapi?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是的因为只能通过office excel打开xsl文件所以只能用exec调用excel打开你上面说jxl或者poi都是提供了对excel文件的读写,不能打开啊 我用下面可以 Runtime run = Runtime.getRuntime(); run.exec("C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE c:\\凭证清单.xls");但是,C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE我怎么知道其他的机子是装在那个目录的呀 对啊,只能这样了,用Runtime.getRuntime().exec()来调用office execl,打开你的xls文件。 问题是,我怎么知道客户端 excel.exe 的路径 . C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE 确实那个路径没办法在java里面得到有很麻烦的办法就是使用jni调用本地方法获取环境变量里面的配置从而找到office路径, 用jni调用本地方法获取环境变量里面的配置从而找到office路径这个方法可以实现 有个笨方法:run.bat:cd\dir EXCEL.EXE/s 再筛选输出内容: Directory of C:\Program Files\Microsoft Office\OFFICE11可以得到:C:\Program Files\Microsoft Office\OFFICE11 直接执行文件 file.xls 系统会自动调用Excel来打开 没有装OFFICE你就不要想打开!~ <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %><%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="/WEB-INF/MultiPages.tld" prefix="MultiPages"%><%@page import="java.util.*"%><%@page import="java.io.*"%><%@page import="java.net.*"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body leftmargin="0" topmargin="0" bgcolor="#FFFFFF"><% response.reset(); String filename = "d:\\program\\excel\\new2.xls" ; response.setContentType("application/vnd.ms-excel"); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { //String ss=request.getRealPath("D:\a.xls"); //System.out.println("path ="+ request.getRealPath(filename)); bis = new BufferedInputStream(new FileInputStream(filename)); //bis = new BufferedInputStream(new FileInputStream(request.getRealPath(filename))); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048]; int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff,0,bytesRead); } } catch(final IOException e) { throw e; } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); }%></body></html> 如果装了excel的话,直接:Runtime run = Runtime.getRuntime();run.exec("excel c:\\凭证清单.xls");就可以打开excel的路径肯定已经设置到path中去了,不用写 关于CJK解码的问题 基本类问题 求问专家(实在在我能力范围外):如何让浏览器安装自订制的jre浏览器插件 java unicode 请大家帮我看看这个java题那里错了 对链表困惑不解 。。。 请问如何算出固定日期距离今天的日期还有多少天? 100分两个小问题 多线程,读写锁 一个RandomAccess中的point问题 请教大侠调试jsp网页的经验 这是怎么回事?
因为只能通过office excel打开xsl文件
所以只能用exec调用excel打开你上面说jxl或者poi都是提供了对excel文件的读写,不能打开啊
Runtime run = Runtime.getRuntime();
run.exec("C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE c:\\凭证清单.xls");
但是,C:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE我怎么知道其他的机子是装在那个目录的呀
有很麻烦的办法就是使用jni调用本地方法获取环境变量里面的配置
从而找到office路径,
从而找到office路径这个方法可以实现
run.bat:
cd\
dir EXCEL.EXE/s 再筛选输出内容:
Directory of C:\Program Files\Microsoft Office\OFFICE11
可以得到:C:\Program Files\Microsoft Office\OFFICE11
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/MultiPages.tld" prefix="MultiPages"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body leftmargin="0" topmargin="0" bgcolor="#FFFFFF">
<%
response.reset();
String filename = "d:\\program\\excel\\new2.xls" ; response.setContentType("application/vnd.ms-excel"); BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
//String ss=request.getRealPath("D:\a.xls");
//System.out.println("path ="+ request.getRealPath(filename));
bis = new BufferedInputStream(new FileInputStream(filename));
//bis = new BufferedInputStream(new FileInputStream(request.getRealPath(filename)));
bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048];
int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
} } catch(final IOException e) {
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
%>
</body>
</html>
Runtime run = Runtime.getRuntime();
run.exec("excel c:\\凭证清单.xls");就可以打开excel的路径肯定已经设置到path中去了,不用写