请问各位大哥大姐,有什么 方法 把页面上的内容保存为 execl 格式? 谢谢,分不够再加!

i8210 2005-05-09 02:52:03
rt
...全文
232 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
woodcord 2005-05-23
  • 打赏
  • 举报
回复
有这样的软件,就是把不同的格式互相转换!
jyy7751 2005-05-23
  • 打赏
  • 举报
回复
可以参考一下,是从数据库是查出的信息,写为EXCEL格式的文件

<%
response.setContentType("application/vnd.ms-excel");
String newname="";
newname="report";
response.setHeader("Content-Disposition","attachment;filename=comm_tj_report("+newname+").xls");
response.flushBuffer();

String filename="";
ResultSet rs=null;
try{
rs=user.executeQuery(sqlStr);
%>

<html>
<body>

<table width="100%" border="1" align="center" >
<tr>
<td height="21">名称</td>
<td height="21">编码</td>
<td height="21">总数量</td>
</tr>
<tr>
<%
filename="www.xls";
String path = request.getRealPath("/"); //取得目前目录在伺服端的实际位置
FileWriter fw = new FileWriter(path + "\\admin\\collection\\xlsfile\\"+filename); //建立FileWrite变量,并设定由fw变量变数引用
while (rs.next())
{
%>
<tr>
<td height="22">
<%
if(rs.getString("community_name")==null){
out.println(" ");
}else{
out.println(rs.getString("community_name"));
}
%>
</td>
<td height="22">

<%
if(rs.getString("community_code")==null){
out.println(" ");
}else{
%>
<%=rs.getString("community_code")%>
<%}%>
</td>
<td height="22">
<%=rs.getString("bsl")%></td>
</tr>
<%
BufferedWriter bw = new BufferedWriter(fw); //建立BufferedWriter变量,并设定由bw变量变数引用
bw.write("编号"+"\t"+"网号"+"\t"+"名称"+"\t"+"查询总数"+"\t");
bw.newLine(); //分行
bw.flush(); //将资料更新至档案
}
fw.close(); //关闭档案
}
catch(Exception e){
out.print(e.getMessage());
}
finally{
try{
if (rs !=null){
rs.close();
rs = null ;
}
}catch( SQLException sqle ) {}
try{
user.getClose();
}
catch( SQLException sqle ) {}
}
%>
</table>
</body>
aqining 2005-05-23
  • 打赏
  • 举报
回复
POI or JXL
anneannean 2005-05-23
  • 打赏
  • 举报
回复
用报表试一下
Iamcoolriver 2005-05-23
  • 打赏
  • 举报
回复
不知道这个对你管用不,用javascript实现的:

<inputtype='button' value='导出EXCEL' LANGUAGE=javascript onclick="exportExcel(datatbl);"></p>
datatbl为你页面上table的名字
function exportExcel(atblData){
if (typeof(EXPORT_OBJECT)!="object"){
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid=clsid:0002E510-0000-0000-C000-000000000046 id=EXPORT_OBJECT></Object>");
}
with (EXPORT_OBJECT){
DataType = "HTMLData";
HTMLData =atblData.outerHTML;
try{
ActiveSheet.Export("C:\\owcToExcel.xls", 0);
alert('汇出完毕');
}
catch (e){
alert('汇出Excel表失败,请确定已安装Excel2000(或更高版本),并且没打开同名xls文件');
}
}
}
i8210 2005-05-23
  • 打赏
  • 举报
回复
up
robbiexie 2005-05-23
  • 打赏
  • 举报
回复
response.setContentType("application/ms-excel;charset=GB2312");
response.setHeader("Content-disposition","attachment; filename=data.xls");
这种方法我用过 没问题
Northwindrocker 2005-05-23
  • 打赏
  • 举报
回复
这样的写excel需要客户端装excel吗?
还是仅仅写出来的文档是xls格式的?
Northwindrocker 2005-05-23
  • 打赏
  • 举报
回复
有谁写过openoffice的接口吗?

是否和excel的接口一样的?
MARS.nEIL 2005-05-10
  • 打赏
  • 举报
回复
学习.帮顶.
grapepaul 2005-05-10
  • 打赏
  • 举报
回复
response.setContentType("application/ms-excel;charset=GB2312");
response.setHeader(
"Content-disposition",
"attachment; filename=data.xls");
i8210 2005-05-10
  • 打赏
  • 举报
回复
难道没人知道吗
wzy19514 2005-05-09
  • 打赏
  • 举报
回复
up
学习

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧