一、jxl 的用法:
缺点:仅限 office2003
特点:代码中,没有用到 FileInputStream
jxl | |
步骤 |
a. 创建输出流 OutputStream os = response.getOutputStream(); response.setHeader("Content-Disposition", "attachment; filename="+new String(fileName.getBytes("gb2312"), "iso-8859-1")); |
b. 创建 WritableWorkbook (也可选择加载模板) WritableWorkbook wwb = Workbook.createWorkbook(os); /** 加载模板 Workbook wb = Workbook.getWorkbook(inputFile); WritableWorkbook wwb = Workbook.createWorkbook(os, wb) */ |
|
c. 创建 WritableSheet (或者选取指定已有sheet) WritableSheet sheet = wwb.createSheet(fileName, 0); /** 指定 sheet WritableSheet sheet = wwb.getSheet("Sheet1"); */ |
|
d. 创建 WritableFont WritableFont wf = new WritableFont(WritableFont.createFont("Arial Unicode MS"), 9); |
|
e. 创建 WritableCellFormat 用于 excel 单元格的格式 WritableCellFormat wcf = new WritableCellFormat(wf); |
|
f. 创建 Label(列 行 从 0 开始) Label label = new Label(column_num, row_num, value, wcf) |
|
g. 添加 cell sheet.addCell(label) |
|
h. 输出,并关闭各文件,各流 wwb.write(); // 写入数据 wwb.close(); // 关闭文件 os.flush(); os.close(); // 关闭数据流 |
时间: 2024-11-14 12:04:08