数据导入到excel 并显示在页面
2007-05-10 10:37
330 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
完全用jxl包
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
首先写java文件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package com.test.excel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.*;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jxl.*;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jxl.write.*;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import jxl.format.*;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.*;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.awt.Color;
![](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 TestExcel ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void writeExcel(OutputStream os) throws Exception ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WritableWorkbook wwb = Workbook.createWorkbook(os);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WritableSheet ws = wwb.createSheet("TestSheet1", 0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Label labelC = new Label(0, 0, "哈哈");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ws.addCell(labelC);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WritableFont wfc = new WritableFont(WritableFont.ARIAL,20, WritableFont.BOLD, false,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
wcfFC.setBackground(jxl.format.Colour.RED);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
labelC = new Label(4, 1, "gagaga呷呷机阿姐阿",wcfFC);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ws.addCell(labelC);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(int i = 5;i<9;i++)...{ //循环操作写单元格
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(int j=0;j<4;j++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
labelC = new Label(j, i, i+""+j);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ws.addCell(labelC);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// 写入Exel工作表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
wwb.write();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// 关闭Excel工作薄对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
wwb.close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// 最好写一个这样的main方法来测试一下你的这个class是否写好了。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args)throws Exception...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
File f=new File("kk.xls");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
f.createNewFile();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writeExcel(new FileOutputStream(f));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
然后在页面显示:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
excel,jsp
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@page import="com.test.excel.TestExcel" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
response.reset();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
response.setContentType("application/vnd.ms-excel");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
TestExcel.writeExcel(response.getOutputStream());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- FH_1Excel报表导入,显示在JSP页面.人为判断后,不正确的数据生成PDF文档
- 把Excel中的数据导入到数据库中并显示在页面
- 将excel中数据显示在页面上,然后再导入到SqlServer数据库中
- winform中 将DataGrid中的数据导入Excel中,并显示Excel应用程序
- winform中 将DataGrid中的数据导入Excel中,并显示Excel应用程序
- 把Excel中的数据导入gridView显示,再导入数据库
- 报表解决Excel导入数据不能根据显示值将实际值存入数据库的问题
- 导入Excel 文件 数据显示成树形式
- c# 导入excel 读取excel数据 多个工作表时 解决科学计数法显示的问题
- 将页面中指定表格的数据导入到Excel中
- 导入excel 文件解析,一行数据,有一列分两行显示,解析时如何 合为一行?
- 把Excel中的数据导入gridView显示,再导入数据库
- Web页面的数据导出excel时的格式问题(长数字显示为科学计数法格式等)
- 在ASP.NET中将Excel文件中数据导入数据库并显示进度条
- springMVC下的后台controller层获取页面导入的excel数据并解析
- 把Excel中的数据导入gridView显示,再导入数据库
- Web页面的数据导出excel时的格式问题(长数字显示为科学计数法格式等)
- [转载]jsp页面显示数据导出到excel表中
- 把Excel中的数据导入gridView显示,再导入数据库
- 页面数据导入Excel